Understand the idea
Ordinary regression commits to ONE global shape for the whole relationship: a single straight line, say. LOESS refuses to make that commitment: instead, at every point along the x-axis, it looks only at the NEARBY data (a local neighborhood), fits a tiny regression using just those nearby points, and reads off the predicted value right there. Do this at every location and stitch the results together, and you get a smooth curve that can bend and flex wherever the data actually suggests it should, without ever writing down one overall equation.
The single dial that matters is the SPAN: what fraction of the data counts as 'nearby' for each local fit. A small span means each local fit only sees a handful of close neighbors, producing a wiggly curve that can chase random noise. A large span means each local fit sees most of the data, producing a stiff, nearly straight curve that can miss real bends. Neither extreme is automatically right; you generally want the SMALLEST span that still looks smooth rather than noisy.
The most important thing to remember about LOESS is what it does NOT give you: there is no equation to write down, no single slope, no p-value. It shows you the SHAPE of a relationship, which is exactly why it is such a useful exploratory tool before committing to a specific parametric model (like a straight line, or a particular polynomial) for a formal analysis.
LOESS and its close cousin LOWESS are locally weighted regression: they fit many small weighted lines through neighborhoods of the data, a form of scatterplot smoothing.
Practitioner explanation
KernelStats fits LOWESS (statsmodels) with a tricube-weighted local linear (degree-1) fit: at target x0, points within the span window are weighted w_i = (1-|(x_i-x0)/d(x0)|^3)^3, and a weighted regression is solved and evaluated at x0. The span (frac, default 2/3) directly trades bias against variance: small span = low bias/high variance (wiggly, chases noise); large span = high bias/low variance (stiff, can miss real structure); and the product's own guidance is to try a couple of values and keep the SMALLEST span that still looks smooth rather than noisy.
Robustifying iterations (default 3, statsmodels' default) down-weight points with large residuals across successive re-fits using bisquare weights, making the curve resistant to outliers; setting iterations=0 disables this and produces plain (non-robust) LOESS. Local pseudo-R-squared (1 - SS_res/SS_tot) is reported as an explicitly DESCRIPTIVE fit-quality measure, not a hypothesis test: there is no F-test or p-value anywhere on this card, and the product states this directly rather than implying inferential machinery that a nonparametric smoother cannot support.
The curve is defined ONLY across the observed range of x: KernelStats does not extrapolate LOESS beyond the data, and the product states this as a hard boundary, not merely a caution. A constant predictor is refused outright (there is no meaningful axis to smooth along), and a constant response returns an honest degenerate-input card (no fabricated pseudo-R-squared) rather than printing a NaN.
When to use it
Consider it when
You want to reveal the SHAPE of the relationship between two continuous variables without committing to a specific formula, for smoothing a scatterplot, checking linearity before running a formal regression, or exploring a trend.
Use caution when
You need an interpretable equation, a slope, or a formal hypothesis test (LOESS provides none of these; use linear, polynomial, or spline regression), the data are sparse (each local window needs enough points to fit reliably), or you intend to read the curve beyond the observed range of the predictor, which is not defined and should never be extrapolated.
Formulas and symbols
Tricube weight
d(x0) the distance to the farthest neighbor within the local window at target location x0; nearby points get more weight.
Local pseudo-R-squared
A descriptive fit measure only: there is no accompanying hypothesis test or p-value for a LOESS smooth.
Assumptions and checks
- With too few points inside each local neighborhood (a small window from a small span fraction or a small sample), the local regression at each point is fit on very little data, making the smooth noisy and unstable in exactly the region being displayed.
In KernelStats: Checked directly: the card computes the number of points in each local window from the span fraction and n, and flags a window of fewer than 5 points as a warning.
- LOESS has no meaningful pattern to describe if the predictor barely varies across the sample; a near-constant predictor gives the smoother almost no signal to work with.
In KernelStats: Checked directly: the card reports the predictor's observed range.
- A LOESS curve is defined only across the range of the predictor actually observed; extrapolating it beyond that range, or reading it as a prediction for a new x outside the training data, has no statistical basis, unlike a parametric model's coefficients.
In KernelStats: Checked directly: the card states the valid predictor range and that the smooth applies only within it, rather than silently extrapolating.
Alternatives
- Linear Regression. The LOESS curve looks essentially straight, or you need an interpretable slope and formal significance test rather than just a picture of the shape.
- Polynomial Regression. The LOESS curve suggests a specific, describable curved shape (a clear quadratic or cubic bend) that you want to fit and interpret as an explicit equation.
- Generalized Additive Model (GAM). You want a smooth, flexible curve like LOESS but combined additively with other predictors in a single interpretable model.
Worked example
Scenario
A LOESS smooth of penguin body mass against flipper length, span = 0.6667, 3 robustifying iterations.
Result
The smooth curve rises steadily and nearly linearly across the observed flipper-length range, with pseudo-R-squared = 0.78 (a straight-line fit gives 0.76) and a structureless residuals-vs-fitted band.
Interpretation
The near-linear shape of the LOESS curve, together with a clean residual pattern, supports the linearity assumption a subsequent formal linear regression of body mass on flipper length would rely on, exactly the diagnostic role LOESS is meant to play before committing to a parametric model.
Dataset: penguins.csv
Common misconceptions
Misconception
The LOESS curve can be read off and trusted for values of the predictor outside the range of the observed data.
Correction
LOESS is defined only across the OBSERVED range of the predictor: each point on the curve depends on nearby real data, and there is no nearby data past the edges of what was observed. Extrapolating a LOESS curve is not supported by the method and should not be done.
Misconception
LOESS gives you a slope you can quote, just like linear regression does, only smoothed.
Correction
LOESS produces a picture of the SHAPE of a relationship, with no single slope, no equation, and no p-value anywhere: it is a nonparametric, exploratory and diagnostic tool. If an interpretable equation or a formal test of significance is the actual goal, a parametric model (linear, polynomial, or spline regression) is the right tool, not LOESS.
References
- Robust Locally Weighted Regression and Smoothing Scatterplots, Cleveland, W. S. (1979), Journal of the American Statistical Association, 74(368), 829-836.
- Locally Weighted Regression: An Approach to Regression Analysis by Local Fitting, Cleveland, W. S. and Devlin, S. J. (1988), Journal of the American Statistical Association, 83(403), 596-610.
