You don't need TensorFlow.js for a trendline.
8 ML algorithms + regression + forecasting. All in ~56KB gzipped. Handles 100 million points in ~1 second.
~56KB gzipped. No dependencies. Won't bloat your app.
k-Means, kNN, Decision Trees, PCA, Logistic Regression, and more.
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 |
| Function | Description | Use When |
|---|---|---|
knnClassifier(data, labels, {k}) |
k-Nearest Neighbours | Simple classification |
logisticRegression(data, labels, opts) |
Logistic regression | Binary classification |
naiveBayes(data, labels) |
Gaussian Naive Bayes | Multi-class classification |
decisionTree(data, labels, {maxDepth}) |
CART decision tree | Interpretable rules |
perceptron(data, labels, opts) |
Single-layer perceptron | Linear separability |
| Function | Description | Use When |
|---|---|---|
kmeans(data, {k}) |
k-Means (Lloyd's + k-means++ init) | Known number of groups |
dbscan(data, {eps, minPoints}) |
Density-based clustering | Unknown clusters + noise |
| Function | Description | Use When |
|---|---|---|
pca(data, {nComponents}) |
Principal Component Analysis | Reduce dimensions, visualise |
seasonalDecompose(data, period) |
Trend + seasonal + residual | Understand time series |
autocorrelation(data, maxLag) |
Autocorrelation function | Find repeating patterns |
detectSeasonality(data) |
Auto-detect period + strength | Unknown periodicity |