arvkevi/kneed
Knee point detection in Python :chart_with_upwards_trend:
What it solves
When working with curves that show diminishing returns — like performance versus cost, or error versus complexity — you often need to spot the "knee" or "elbow" where adding more of one thing stops being worth it. kneed automates this by detecting that point of maximum curvature, so you don't have to guess from a plot.
How it works
You supply two equal-length arrays of x and y values. kneed uses the Kneedle algorithm to compute the curvature and returns the x-value where the curve bends most sharply. You can tell it whether the curve is concave or convex and whether the function increases or decreases, or let it auto-detect those with find_shape(). A sensitivity parameter S lets you adjust how aggressively it looks for a knee, and you can choose between linear or polynomial interpolation. It can also find multiple knees when run in online mode (all_knees / all_elbows). Two built-in plotting functions let you quickly visualize the normalized or raw data with the knee marked.
Who it’s for
Data scientists, analysts, and researchers who need a reproducible, numeric way to pick breakpoints in curves — for example, choosing the number of clusters, setting a threshold, or finding an optimal operating point. It's especially handy if you're implementing the Kneedle method from the literature.
Highlights
- Detects knees/elbows in both concave and convex curves, with increasing or decreasing functions.
- Auto-detects curve shape and direction with find_shape().
- Supports multiple knee detection via online mode (all_knees / all_elbows).
- Tunable sensitivity parameter S for fine control.
- Two interpolation methods: interp1d and polynomial.
- Built-in plotting functions for quick visual checks.
- Installable via pip or conda-forge, with optional plotting dependencies.
Related
- Project
- Project
- Project
- Project