Skip to content
/ kneebow Public
forked from georg-un/kneebow

Knee or elbow detection for curves

License

Notifications You must be signed in to change notification settings

asmyoo/kneebow

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kneebow

Find the knee of a curve or the elbow of a curve.

Codacy Badge Build Status codecov

How it works

kneebow builds upon a very simple idea: if we want to find the elbow of a curve, we can simply rotate the data so that curve looks down and then take the minimum value. If we want to find the knee of the curve, we take the maximum value instead. It's as simple as that.

For more info, see this answer on the Data Science StackExchange.

Installation

You can install the package via pip:

pip install kneebow

Alternatively, you can also install the latest version from GitHub:

pip install git+https://github.com/georg-un/kneebow.git

Usage

Let's assume, we try to find the elbow of the following data:

import numpy as np
data = np.array([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8],  # linear until (8,8)
                 [9, 16], [10, 32], [11, 64], [12, 128], [13, 256], [14, 512]])   # exponential afterwards

Let's have a peak how this data looks like:

data_plot

To find the elbow, we create an instance of the Rotor class and use its fit_rotate method:

from kneebow.rotor import Rotor
 
rotor = Rotor()
rotor.fit_rotate(data)

Now we can get the index of the elbow as follows:

elbow_idx = rotor.get_elbow_index()
print(elbow_idx)  # 11

The Rotor class also comes with plot methods to inspect the data visually together with the estimated elbow/knee:

rotor.plot_elbow()

rotor_plot

License

Distributed under the MIT License. See LICENSE for more information.

About

Knee or elbow detection for curves

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%