Skip to content

Implementation of LOWESS (Locally Weighted Scatterplot Smoothing) algorithm with bootstrap confidence intervals for nonparametric regression and data smoothing in Python.

License

Notifications You must be signed in to change notification settings

esosetrov/LOWESS-Smoother-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LOWESS-Smoother-Implementation

Implementation of LOWESS (Locally Weighted Scatterplot Smoothing) algorithm with bootstrap confidence intervals for nonparametric regression and data smoothing in Python.

Overview

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

Features

  • 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

Installation

# Clone repository
git clone https://github.com/esosetrov/LOWESS-Smoother-Implementation.git
cd LOWESS-Smoother-Implementation

Install dependencies

pip install numpy matplotlib seaborn statsmodels pandas

Usage

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

Results

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

Algorithm Details

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

Applications

  • 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

Project Structure

LOWESS-Smoother-Implementation/
├── lowess-smoother-algorithm.ipynb
├── README.md
├── LICENSE
├── .gitignore
└── requirements.txt

Dependencies

  • Python 3.10+;
  • numpy;
  • matplotlib;
  • seaborn;
  • statsmodels;
  • pandas;

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

References

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

Note:

This notebook is designed for educational and research purposes. Real-world applications may require additional considerations and validation.

Releases

No releases published

Packages

No packages published