Implementation of LOWESS (Locally Weighted Scatterplot Smoothing) algorithm with bootstrap confidence intervals for nonparametric regression and data smoothing in Python.
LOWESS is a powerful nonparametric technique proposed by Cleveland (1979) for modeling and smoothing two-dimensional data. This method is particularly useful for:
- Data smoothing - Extracting trends from noisy data
- Outlier detection - Identifying anomalies relative to local trends
- Forecasting - Building flexible regression models for volatile data
- Seasonal analysis - Handling periodic and evolutionary data series
- LOWESS smoothing with customizable bandwidth
- Bootstrap confidence intervals (95% CI)
- Nonlinear data handling - perfect for cosine-like patterns
- Interactive visualization with matplotlib and seaborn
- Statistical robustness - resistant to outliers
# Clone repository
git clone https://github.com/esosetrov/LOWESS-Smoother-Implementation.git
cd LOWESS-Smoother-Implementationpip install numpy matplotlib seaborn statsmodels pandas
import numpy as np
import statsmodels.api as sm
# Generate sample data
x = np.random.uniform(0, 4 * np.pi, size=200)
y = np.cos(x) + np.random.random(size=len(x))
# Apply LOWESS smoothing
smoothed = sm.nonparametric.lowess(exog=x, endog=y, frac=0.2)
# Compute confidence intervals
from lowess_bootstrap import lowess_with_confidence_bounds
eval_x = np.linspace(0, 4 * np.pi, 31)
smoothed, bottom, top = lowess_with_confidence_bounds(
x, y, eval_x, lowess_kw={"frac": 0.1}
)The implementation demonstrates:
- Smooth curve fitting through noisy data
- 95% confidence intervals via bootstrap resampling
- Effective handling of nonlinear patterns
- Robust performance in presence of outliers
LOWESS works by:
- Local fitting - Estimating each point using its neighbors
- Weighted regression - Using tricube weighting function
- Iterative refinement - Downweighting outliers in subsequent iterations
- Bootstrap validation - Assessing uncertainty through resampling
- Genetics research - Gene expression data analysis
- Financial modeling - Time series smoothing
- Signal processing - Noise reduction
- Quality control - Trend detection in manufacturing
- Environmental science - Climate data analysis
LOWESS-Smoother-Implementation/
├── lowess-smoother-algorithm.ipynb
├── README.md
├── LICENSE
├── .gitignore
└── requirements.txt
- Python 3.10+;
- numpy;
- matplotlib;
- seaborn;
- statsmodels;
- pandas;
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Cleveland, William S. (1979). "Robust Locally Weighted Regression and Smoothing Scatterplots". Journal of the American Statistical Association. Statsmodels Documentation: https://www.statsmodels.org Harrell, Frank E. Jr. "Regression Modeling Strategies" https://www.kaggle.com/code/eugeniyosetrov/lowess-smoother-algorithm
This notebook is designed for educational and research purposes. Real-world applications may require additional considerations and validation.