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.
pip install loessVerified import paths — ran on the pinned version, not inferred.
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.
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`.
Pre-process your data to handle missing values (e.g., imputation, removal) or infinite values before passing them to the LOESS functions.
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.
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.
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]`.
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.