kneed
kneed copied to clipboard
can not detect knee/elbow point in python 3.9
Hi guys, Not sure if as below showing, it not supports 3.9x?
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()
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()
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:
Because downsampled, the data now shows a real elbow!
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!