GithubHelp home page GithubHelp logo

Comments (6)

Peterdha avatar Peterdha commented on July 19, 2024 1

Hi @arvkevi , have been looking a bit closer at the code, I can't see anything wrong with your implementation, however I do believe the algorithm is flawed.
In the case where there is some jitter on the curve we want to find a knee for, it means we have a lot of local maxima and minima. This results in always resetting the threshold, resulting in outputting as a knee the last local max that was found.
My guess is the smoothing step is the culprit here, as a choice for a spline will always pass through the datapoints themselves. In my case that means the jitter stays in!
So I hacked "exponentially weighted moving average" in, as mentioned in the article to be an alternative for splines,
works like a charm now :-) !
As illustrated below.
Using the solution from Divakar on https://stackoverflow.com/questions/42869495/numpy-version-of-exponential-weighted-moving-average-equivalent-to-pandas-ewm

However the S-factor doesn't do a whole lot for me...
image

from kneed.

arvkevi avatar arvkevi commented on July 19, 2024

Thanks Peter, I'll look into this and I'm especially interested to see if S is working as expected.

from kneed.

arvkevi avatar arvkevi commented on July 19, 2024

Thanks for spending some time with the code @Peterdha

My guess is the smoothing step is the culprit here, as a choice for a spline will always pass through the datapoints themselves. In my case that means the jitter stays in!
This is what I originially thought could be the issue -- that perhaps your function was in a local maxima.

Do you think it's worthwhile to implement a better spline method? Or provide a keyword argument to implement ewma as an option?

I tried modifying the source code to kind='cubic' and kind='quadratic'

uspline = interpolate.interp1d(self.x, self.y, kind='cubic')

with no success eliminating the steps in your function.

from kneed.

Peterdha avatar Peterdha commented on July 19, 2024

hi @arvkevi

Do you think it's worthwhile to implement a better spline method? Or provide a keyword argument to implement ewma as an option?

I'm not sure if ewma is a good solution here, as it requires some tweaking to get a nice smooth curve.
Instead I would try to fit a higher order polynomial through it, for the use-cases I can imagine 5-7 order polynomial should suffice. (https://scikit-learn.org/stable/auto_examples/linear_model/plot_polynomial_interpolation.html#sphx-glr-auto-examples-linear-model-plot-polynomial-interpolation-py)

But then, if you go through the trouble of fitting a nice curve, you could just as well calculate the max of second derivative to get the knee point...

from kneed.

arvkevi avatar arvkevi commented on July 19, 2024

Thanks @Peterdha
I'm thinking to leave the algorithm as-is for now.
I'll create a branch to work on this a bit, reference this issue and maybe others will chime in 😄

from kneed.

arvkevi avatar arvkevi commented on July 19, 2024

fixed by #26

from kneed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.