You don't need TensorFlow.js for a trendline.
Most apps just need simple predictions: forecast sales, smooth sensor data, add a trendline. ~40KB gzipped. Handles 100 million points in ~1 second.
~40KB gzipped. No dependencies. Won't bloat your app.
Regression, smoothing, forecasting. Does one thing well.
100M points in ~1s. 1M points in ~10ms.
One function, one purpose. No configuration needed.
Full type definitions. Autocomplete everything.
Browser, Node.js, Web Workers.
Predict next month's revenue
Add trend lines and moving averages to charts
Predict goal completion date
Smooth noisy sensor readings
Find doubling time and growth rate
Find spikes and unusual values
Model diminishing returns
Fit parabolas and polynomials
| Function | Description | Use When |
|---|---|---|
linearRegression(x, y) |
Fits y = mx + b | Steady growth/decline |
linearRegressionSimple(y) |
Same, auto x = [0,1,2...] | Time series data |
polynomialRegression(x, y, {degree}) |
Fits polynomial curve | Curved patterns |
exponentialRegression(x, y) |
Fits y = a ร e^(bx) | Growth/decay |
logarithmicRegression(x, y) |
Fits y = a + b ร ln(x) | Diminishing returns |
powerRegression(x, y) |
Fits y = a ร x^b | Power laws |
| Function | Description | Use When |
|---|---|---|
sma(data, window) |
Simple Moving Average | General smoothing |
ema(data, window) |
Exponential Moving Average | Recent values matter more |
wma(data, window) |
Weighted Moving Average | Balance of both |
exponentialSmoothing(data, {alpha}) |
Single exponential smooth | Quick smoothing |
| Function | Description | Use When |
|---|---|---|
trendForecast(data, periods) |
Analyze trend + predict | Future predictions |
predict(xTrain, yTrain, xNew) |
One-liner predict | Quick predictions |
trendLine(data, periods) |
Get model + predictions | Need both |
| Function | Description | Use When |
|---|---|---|
findPeaks(data) |
Find local maxima | Detect spikes |
findTroughs(data) |
Find local minima | Detect dips |
rateOfChange(data, periods) |
% change from n ago | Growth rate |
momentum(data, periods) |
Difference from n ago | Trend strength |