LOESS Smoothing Library

2.1.2 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →