Registry / data / loess
library2.1.2pypypi✓ verified 85d ago

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 loess
INSTALL
IMPORT
SIG · LOESS
L
loess
datapythonv2.1.2
Install
11.6s avg
Import
250ms
Disk
322MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.246s · 319.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 11.6s · import 0.255s · 306MB
322MB installed
● package 322MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

loess_1d
from loess.loess_1d import loess_1d
loess_2d
from loess.loess_2d import loess_2d

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.

import numpy as np from loess.loess_1d import loess_1d # Generate some sample data with noise x = np.linspace(0, 10, 100) y = np.sin(x) + np.random.normal(0, 0.5, 100) # Apply LOESS smoothing # x must be sorted for loess_1d y_smoothed, w_out = loess_1d(x, y, xnew=x, span=0.5, degree=1) print(f"Original x (first 5): {x[:5]}") print(f"Original y (first 5): {y[:5]}") print(f"Smoothed y (first 5): {y_smoothed[:5]}") print(f"Shape of smoothed y: {y_smoothed.shape}")
Debug
Known issues
gotchaThe 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`.
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`.
affects: All versions
gotchaInput 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.
fix
Pre-process your data to handle missing values (e.g., imputation, removal) or infinite values before passing them to the LOESS functions.
affects: All versions
gotchaThe `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`.
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.
affects: All versions
Errors
Common errors & fixes
ValueError: array must not contain infs or NaNs
One or more of the input arrays (`x`, `y`, `z`) contains infinite (`inf`) or Not-a-Number (`NaN`) values.
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.
ValueError: x must be sorted for this algorithm to work
The input array `x` for `loess_1d` was not provided in ascending sorted order.
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]`.
ValueError: span must be between 0.0 and 1.0
The `span` parameter was set to a value outside the valid range (0.0, 1.0].
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.
Upgrade
Version history
2.1.2latest on PyPI · released May 20, 2024
Audit
Dependencies
numpyrequiredRequired for numerical operations and array handling.
scipyrequiredRequired for statistical functions and interpolation.
Agent activity
10 hits · last 30 days
node
6
Resources
loess — pip install loess · libregistry