Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not detect knee/elbow point in python 3.9 #122

Open
kk120120 opened this issue May 12, 2022 · 2 comments
Open

can not detect knee/elbow point in python 3.9 #122

kk120120 opened this issue May 12, 2022 · 2 comments

Comments

@kk120120
Copy link

kk120120 commented May 12, 2022

Hi guys,
Not sure if as below showing, it not supports 3.9x?

image

If it is supposed to support 3.9x, the below most probably is an issue.
Thanks!

===================================
Python 3.9.7
Name: kneed
Version: 0.7.0

import scipy.stats as st
import plotly.express as px
import numpy as np
import kneed as kd

x2 = np.linspace(-3,3,500)
y2 = np.apply_along_axis(st.norm.cdf,0,x2)

fig = px.line(x=x2,y=y2)
fig.update_layout(height=600,
                  width=900,
                  title="-3到+3正态分数据的布累积概率图"
                 )
fig.show()

newplot

def find_elbows(c,d,fc=0):
    ew = kd.KneeLocator(x=x2,y=y2,S=fc,
                     curve=c,
                     direction=d,
                     online=False
                    )
    return ew

ews = [ find_elbows(x,y) for x in ['concave','convex'] for y in ['increasing','decreasing']]

for x in ews:
    x.plot_knee()

plot2--

@AdrienWehrle
Copy link

AdrienWehrle commented May 12, 2022

This issue was most likely raised due to the use of a very smooth curve with default parameters, and not because of the Python version. Reducing x2 to e.g. np.linspace(-3,3,500)[::80] and plotting find_elbows('convex', 'increasing').plot_knee() gives the following:
Figure_4

Because downsampled, the data now shows a real elbow!

@arvkevi
Copy link
Owner

arvkevi commented May 12, 2022

This seems like a good use case to set online=True. The documentation discusses how setting this will alter the identification of knee points by self-correcting and avoiding local maxima. I don't think the "issue" above is primarily a function of the smooth line. I also don't think it's a Python 3.9 issue, I just ran some tests in a Python 3.9 env locally.

I find it helpful to use plot_normalized_knee() to look at the difference curve when cases like these arise. The knee should, in theory, be the max value of the difference curve.

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants