Quick Start

Get up and running with LOWESS in minutes.

Basic Smoothing

Smooth a noisy sine wave — the kind of signal where LOWESS shines. Each example recovers the underlying trend from 100 points of Gaussian noise.

using FastLOWESS, Random, Printf

# 100-point noisy sine wave
x = collect(range(0, 2π, length=100))
rng = MersenneTwister(42)
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(; fraction=0.3, iterations=3)
result = fit(model, x, y)

@printf "First smoothed value: %.4f  (true: %.4f)\n" result.y[1] sin(x[1])
First smoothed value: 0.3539  (true: 0.0000)

With Confidence Intervals

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

model = Lowess(;
    fraction=0.5,
    iterations=3,
    outputs=["diagnostics"],
    intervals=(confidence=0.95, prediction=0.95),
)
result = fit(model, x, y)

println("Smoothed: ", result.y)
println("CI Lower: ", result.confidence_lower)
println("CI Upper: ", result.confidence_upper)
println("R2: ", result.diagnostics.r_squared)
Smoothed: [0.4003134529833126, 0.41060415969103753, 0.42251389238771603, 0.4360677268953081, 0.45121012253337694, 0.4678679072422548, 0.4859033047161452, 0.5051391765786739, 0.5253444980373881, 0.5462614314039487, 0.5677166398850683, 0.5895636056806488, 0.6116073209705905, 0.6336171299055736, 0.6553658282949861, 0.6765936120634118, 0.697091366028896, 0.7167147677635648, 0.7352089888428974, 0.7522498953381389, 0.7676063634897884, 0.781079450903968, 0.7925628466133685, 0.8019489831483568, 0.8090952835574589, 0.8139459377752782, 0.8164731020262288, 0.8167337681953073, 0.8146628010464234, 0.8100940781025444, 0.8027877595872238, 0.7925177755701991, 0.7790615521722606, 0.7622625412960009, 0.7420326530780406, 0.7183318174374389, 0.6911140155528906, 0.6603589379604191, 0.6261067971034968, 0.5886382689445464, 0.5483383120222627, 0.5057314892696259, 0.4613544234192828, 0.4157076519205944, 0.36924246045830317, 0.3221750356674448, 0.27449095590075145, 0.22625648934524883, 0.1776231320219357, 0.12875406316140325, 0.07993278898160057, 0.03153196707136202, -0.01606966208118154, -0.06255365783181732, -0.10775876502883429, -0.15162626957328595, -0.19422823462391353, -0.23561734856363528, -0.2759057124321589, -0.31525269774133313, -0.35375805887570644, -0.3913331832088972, -0.427744998601217, -0.46273456201128566, -0.49610318430127676, -0.527601797924216, -0.5569999258093233, -0.5841122705627431, -0.6087845015705834, -0.6309942962922328, -0.6507182280476271, -0.6679692473299977, -0.6827356376755115, -0.695020574326366, -0.7048504215279287, -0.7122019650446657, -0.7169935031894841, -0.7190406148455402, -0.7182226245179533, -0.7146336821554389, -0.7084743520492307, -0.6999274572701506, -0.6891871477142509, -0.676497123095278, -0.662100307238463, -0.6461809972958956, -0.6290408579146058, -0.6110530218665884, -0.5926311251865543, -0.5740838470834283, -0.5555913971094661, -0.5371310474927065, -0.5186316341633216, -0.4999543333337098, -0.4809888209591344, -0.4617393934080526, -0.4423777485188271, -0.42312382154759537, -0.4041730209196564, -0.38577029380729144]
CI Lower: [0.351241290399097, 0.3587052764339, 0.3675001147634977, 0.37772154817984127, 0.3894057745265893, 0.4025370986837404, 0.4170504448468578, 0.4328467584286806, 0.4497706404282378, 0.467620437774231, 0.4862255475166192, 0.5054335200093891, 0.5250542894896667, 0.5448686459127327, 0.5646553823037764, 0.5841634012899821, 0.6031740018594576, 0.6214894345925829, 0.6388122291214168, 0.6547884317303148, 0.6691610134233003, 0.6817176202229447, 0.6923376596063614, 0.7009111058204931, 0.7073029467049881, 0.7114686783288553, 0.7134085387294961, 0.7131954763012739, 0.7107541943858081, 0.7058842982462625, 0.6983420718922219, 0.6879152200106622, 0.6744161145067665, 0.657726541442103, 0.6378027900834755, 0.6146395811559513, 0.5881731818587179, 0.5583626914617357, 0.5252129099221743, 0.4889422264381065, 0.4498679185244896, 0.40844034518085676, 0.3651011509237807, 0.32026029388488364, 0.27428859648421194, 0.22735444820111883, 0.17944160397717313, 0.13065826936504266, 0.08123632310503363, 0.03144696190368827, -0.01832864538240274, -0.06765054509803148, -0.11608505884915873, -0.16325737810265953, -0.20895161797341436, -0.2531258948462748, -0.2958945535603624, -0.3373394398447224, -0.3775964814617079, -0.416836567551466, -0.45520049204318264, -0.49263172086194307, -0.5289110621708294, -0.5637753372568542, -0.5970304877390055, -0.6284200466126896, -0.6577113655149207, -0.684736362745164, -0.7093441108054753, -0.7315032731280089, -0.7511736311799818, -0.7683396971544533, -0.7829923010581584, -0.7951713449420978, -0.804920517836492, -0.8122306288918433, -0.8169832767735049, -0.8189347668752465, -0.8178992547570209, -0.813943856486641, -0.8072555776289367, -0.7980170932715499, -0.786430815634265, -0.7727566253607184, -0.7572494276312605, -0.7400963753009939, -0.7216375357671968, -0.7022851453993202, -0.6824871876960243, -0.6625898710071354, -0.6427787302771318, -0.6229972286719873, -0.6031463128107801, -0.5830395044864196, -0.5625198747139393, -0.5415611761475083, -0.5203349740543871, -0.4990662404956386, -0.47796615585134966, -0.4573078521542019]
CI Upper: [0.4493856155675282, 0.46250304294817507, 0.47752767001193436, 0.4944139056107749, 0.5130144705401646, 0.5331987158007692, 0.5547561645854325, 0.5774315947286672, 0.6009183556465385, 0.6249024250336663, 0.6492077322535174, 0.6736936913519085, 0.6981603524515142, 0.7223656138984146, 0.7460762742861958, 0.7690238228368416, 0.7910087301983344, 0.8119401009345467, 0.8316057485643781, 0.8497113589459631, 0.8660517135562765, 0.8804412815849914, 0.8927880336203756, 0.9029868604762206, 0.9108876204099297, 0.9164231972217012, 0.9195376653229616, 0.9202720600893407, 0.9185714077070387, 0.9143038579588263, 0.9072334472822258, 0.897120331129736, 0.8837069898377546, 0.8667985411498988, 0.8462625160726056, 0.8220240537189265, 0.7940548492470634, 0.7623551844591026, 0.7270006842848193, 0.6883343114509863, 0.6468087055200358, 0.603022633358395, 0.5576076959147849, 0.5111550099563051, 0.4641963244323944, 0.4169956231337708, 0.3695403078243298, 0.321854709325455, 0.27400994093883774, 0.22606116441911822, 0.17819422334560386, 0.13071447924075552, 0.08394573468679567, 0.038150062439024884, -0.006565912084254222, -0.05012664430029713, -0.09256191568746465, -0.13389525728254814, -0.17421494340260987, -0.2136688279312003, -0.25231562570823024, -0.29003464555585134, -0.32657893503160457, -0.36169378676571706, -0.39517588086354805, -0.42678354923574247, -0.45628848610372597, -0.48348817838032215, -0.5082248923356915, -0.5304853194564567, -0.5502628249152725, -0.5675987975055422, -0.5824789742928645, -0.5948698037106341, -0.6047803252193653, -0.6121733011974881, -0.6170037296054632, -0.6191464628158339, -0.6185459942788857, -0.6153235078242367, -0.6096931264695247, -0.6018378212687513, -0.5919434797942369, -0.5802376208298375, -0.5669511868456656, -0.5522656192907973, -0.5364441800620149, -0.5198208983338566, -0.5027750626770842, -0.48557782315972126, -0.46840406394180045, -0.45126486631342566, -0.43411695551586305, -0.41686916218100006, -0.39945776720432963, -0.38191761066859686, -0.3644205229832671, -0.34718140259955216, -0.33037988598796314, -0.314232735460381]
R2: 0.7909162309681064

Handling Outliers

LOWESS can robustly handle outliers through iterative reweighting:

using FastLOWESS
using Random, Statistics

rng = MersenneTwister(42)
x = collect(range(0, 2π, length=100))
y = sin.(x) .+ randn(rng, 100) .* 0.3

x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
y_with_outlier = [2.0, 4.0, 6.0, 50.0, 10.0, 12.0]

model = Lowess(;
    fraction=0.7,
    iterations=5,
    robustness_method="bisquare",
    outputs=["weights"]
)
result = fit(model, x, y_with_outlier)

# Check which points were downweighted
for (i, w) in enumerate(result.robustness_weights)
    if w < 0.5
        println("Point $i is likely an outlier (weight: $(round(w, digits=3)))")
    end
end
Point 4 is likely an outlier (weight: 0.0)

Streaming Mode

For datasets too large to fit in memory, stream them in fixed-size chunks with overlap.

using FastLOWESS, Random

x = collect(range(0, 10π, length=5000))
rng = MersenneTwister(42)
y = @. sin(x / π) * exp(-x / 30) + randn(rng) * 0.15

model = StreamingLowess(; fraction=0.2, chunk_size=1000, overlap=100,
                          merge_strategy="weighted_average")

chunk_size = 1000
for start in 1:chunk_size:4001
    stop = min(start + chunk_size - 1, length(x))
    process_chunk(model, x[start:stop], y[start:stop])
end
result = finalize(model)
println("Smoothed $(length(result.y)) points in streaming mode")
Smoothed 100 points in streaming mode

Next Steps

TopicLink
How LOWESS worksConcepts
All parameters explainedAPI Reference
Batch vs Streaming vs OnlineExecution Modes
Edge handlingBoundary
Outlier handling in depthRobustness
Full API per languageAPI Reference