{"id":4599,"library":"kneed","title":"Knee-point detection in Python","description":"kneed is a Python library (current version 0.8.6) for detecting knee (also known as elbow) points in curves. It implements the Kneedle algorithm to identify the point of maximum curvature in a given set of x and y values. The library is actively maintained with regular patch releases and occasional feature updates.","status":"active","version":"0.8.6","language":"en","source_language":"en","source_url":"https://github.com/arvkevi/kneed","tags":["data-analysis","knee-point-detection","elbow-method","clustering","time-series"],"install":[{"cmd":"pip install kneed","lang":"bash","label":"Core functionality"},{"cmd":"pip install kneed[plot]","lang":"bash","label":"With Matplotlib for plotting"}],"dependencies":[{"reason":"Required for plotting functions within KneeLocator (e.g., plot_knee(), plot_knee_normalized()). Optional since v0.8.0.","package":"matplotlib","optional":true}],"imports":[{"symbol":"KneeLocator","correct":"from kneed import KneeLocator"},{"note":"Utility class for generating sample data, often used in examples.","symbol":"DataGenerator","correct":"from kneed import DataGenerator"},{"note":"Helper function to automatically detect curve shape and direction.","symbol":"find_shape","correct":"from kneed import find_shape"}],"quickstart":{"code":"import numpy as np\nfrom kneed import KneeLocator, find_shape\n\n# Example 1: Basic usage with known curve type and direction\nx = np.arange(1, 11)\ny = np.array([1, 2, 3, 4, 5, 5.5, 5.6, 5.7, 5.8, 5.9])\n\nkl = KneeLocator(x, y, curve=\"concave\", direction=\"increasing\")\nprint(f\"Knee at x: {kl.knee}\")\nprint(f\"Corresponding y: {kl.knee_y}\")\n\n# Example 2: Using find_shape for auto-detection\nx_auto = np.arange(1, 101)\ny_auto = np.sin(x_auto / 10) + np.log(x_auto) + np.random.rand(100)\n\nauto_direction, auto_curve = find_shape(x_auto, y_auto)\nkl_auto = KneeLocator(x_auto, y_auto, curve=auto_curve, direction=auto_direction)\nprint(f\"\\nAuto-detected curve: {auto_curve}, direction: {auto_direction}\")\nprint(f\"Knee at x (auto-detected): {kl_auto.knee}\")","lang":"python","description":"This quickstart demonstrates how to use `KneeLocator` to find a knee point in a dataset, both by manually specifying `curve` and `direction`, and by automatically detecting them using `find_shape`. The `knee` and `knee_y` attributes provide the x and y coordinates of the detected knee point."},"warnings":[{"fix":"Ensure Matplotlib is installed using `pip install kneed[plot]` if plotting functionality is required.","message":"Matplotlib became an optional dependency in v0.8.0. Code calling plotting methods (e.g., `plot_knee()`, `plot_knee_normalized()`) will now raise a `ModuleNotFoundError` if Matplotlib is not installed via `pip install kneed[plot]`.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Explicitly install `scikit-learn` if your application requires it: `pip install scikit-learn`.","message":"The `scikit-learn` dependency was removed in v0.7.0. While `kneed` itself does not directly rely on `scikit-learn` for its core algorithm, code that implicitly expected `scikit-learn` to be installed alongside `kneed` (e.g., for K-Means clustering examples) might now fail.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Always use valid string values: `curve` can be 'concave' or 'convex'; `direction` can be 'increasing' or 'decreasing'.","message":"As of v0.7.0, `kneed` validates the `curve` and `direction` arguments. Providing invalid string values for these parameters will now result in an error, whereas they might have been silently ignored or led to incorrect behavior in previous versions.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Check the `knee` attribute directly; if no knee is found, `kl.knee` will be `None`. Adjust error handling or logging based on this programmatic check instead of relying on warning messages.","message":"Beginning with v0.8.4 and further refined in v0.8.5, `kneed` no longer emits warnings when no knee/elbow point is found. Users who previously relied on parsing these warnings for error handling or informational purposes should update their logic.","severity":"gotcha","affected_versions":">=0.8.4"},{"fix":"Carefully consider the shape and trend of your data. Use `find_shape()` for automatic detection, or plot your data to visually determine the correct parameters. Experiment with different `S` values as well.","message":"The `curve` and `direction` parameters are critical for accurate knee detection. An incorrect choice (e.g., `curve='concave'` for a convex elbow, or `direction='increasing'` for a decreasing curve) will lead to incorrect or no knee detection.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Experiment with different `S` values (e.g., 0.1 to 10.0) based on your data's noise level and expected knee sharpness. Consider using `interp_method='polynomial'` and `polynomial_degree` for smoother curves in noisy data.","message":"The sensitivity parameter `S` (default `1.0`) greatly influences knee detection. Smaller `S` values detect knees more aggressively/earlier, while larger values are more conservative. Improper `S` can lead to missing a knee or identifying a false one, especially with noisy data.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}