{"id":7381,"library":"loess","title":"LOESS Smoothing Library","description":"LOESS (Locally Estimated Scatterplot Smoothing) is a non-parametric regression method that fits simple models to localized subsets of data to build up a function that describes the deterministic part of the variation. This Python library provides robust implementations for 1D and 2D LOESS smoothing. The current version is 2.1.2, and it typically sees releases for bug fixes and minor improvements, with a stable API.","status":"active","version":"2.1.2","language":"en","source_language":"en","source_url":"https://github.com/crdante/loess","tags":["statistics","smoothing","regression","data science","non-parametric"],"install":[{"cmd":"pip install loess","lang":"bash","label":"Install loess"}],"dependencies":[{"reason":"Required for numerical operations and array handling.","package":"numpy","optional":false},{"reason":"Required for statistical functions and interpolation.","package":"scipy","optional":false}],"imports":[{"symbol":"loess_1d","correct":"from loess.loess_1d import loess_1d"},{"symbol":"loess_2d","correct":"from loess.loess_2d import loess_2d"}],"quickstart":{"code":"import numpy as np\nfrom loess.loess_1d import loess_1d\n\n# Generate some sample data with noise\nx = np.linspace(0, 10, 100)\ny = np.sin(x) + np.random.normal(0, 0.5, 100)\n\n# Apply LOESS smoothing\n# x must be sorted for loess_1d\ny_smoothed, w_out = loess_1d(x, y, xnew=x, span=0.5, degree=1)\n\nprint(f\"Original x (first 5): {x[:5]}\")\nprint(f\"Original y (first 5): {y[:5]}\")\nprint(f\"Smoothed y (first 5): {y_smoothed[:5]}\")\nprint(f\"Shape of smoothed y: {y_smoothed.shape}\")","lang":"python","description":"This quickstart demonstrates how to use `loess_1d` to smooth a one-dimensional dataset. It generates noisy sinusoidal data and then applies LOESS, printing the first few original and smoothed values. Ensure your `x` array is sorted."},"warnings":[{"fix":"Ensure `x` is sorted before passing it to `loess_1d`. For example: `x_sorted, y_sorted = x[x.argsort()], y[x.argsort()]` if `y` needs to be reordered along with `x`.","message":"The input array `x` for `loess_1d` must be sorted in ascending order. If `x` is not sorted, the algorithm will not work correctly and will raise a `ValueError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pre-process your data to handle missing values (e.g., imputation, removal) or infinite values before passing them to the LOESS functions.","message":"Input data (`x`, `y` for 1D; `x`, `y`, `z` for 2D) must not contain `inf` or `NaN` values. The library performs checks and will raise a `ValueError` if these are present.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `span` to a value between 0.0 and 1.0 (e.g., 0.5 for half the data points). Experiment with different `span` values to find the optimal smoothing for your data.","message":"The `span` parameter (also known as `alpha` or `bandwidth`) is expected to be a float between 0.0 and 1.0 (exclusive of 0.0, inclusive of 1.0), representing the fraction of data points used for each local regression. Providing a value outside this range will result in a `ValueError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Filter out or impute `NaN` and `inf` values from your data before passing them to `loess_1d` or `loess_2d`. Example: `x = x[~np.isnan(x)]` and similarly for other arrays.","cause":"One or more of the input arrays (`x`, `y`, `z`) contains infinite (`inf`) or Not-a-Number (`NaN`) values.","error":"ValueError: array must not contain infs or NaNs"},{"fix":"Sort your `x` array. If `y` data corresponds to `x`, ensure `y` is reordered accordingly: `sort_idx = np.argsort(x); x_sorted = x[sort_idx]; y_sorted = y[sort_idx]`.","cause":"The input array `x` for `loess_1d` was not provided in ascending sorted order.","error":"ValueError: x must be sorted for this algorithm to work"},{"fix":"Adjust the `span` parameter to be a float value greater than 0.0 and less than or equal to 1.0. For example, `span=0.5` is a common starting point.","cause":"The `span` parameter was set to a value outside the valid range (0.0, 1.0].","error":"ValueError: span must be between 0.0 and 1.0"}]}