Loading WASM module...

micro-ml

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.

TensorFlow.js 500KB vs micro-ml ~40KB
GitHub npm Try Live Demo
npm install micro-ml

Why micro-ml?

๐Ÿ“ฆ

Small

~40KB gzipped. No dependencies. Won't bloat your app.

๐ŸŽฏ

Focused

Regression, smoothing, forecasting. Does one thing well.

โšก

Scales

100M points in ~1s. 1M points in ~10ms.

๐Ÿงฉ

Simple API

One function, one purpose. No configuration needed.

๐Ÿ”’

TypeScript

Full type definitions. Autocomplete everything.

๐ŸŒ

Works Everywhere

Browser, Node.js, Web Workers.

TensorFlow.js

500KB+
Neural networks, full ML

ml.js

150KB
General ML toolkit

simple-statistics

30KB
Basic statistics

micro-ml

40KB
Regression & forecasting

Performance (Linear Regression)

-
1,000 points
-
10,000 points
-
100,000 points
-
1,000,000 points

What Can You Build?

๐Ÿ“ˆ Sales Forecasting

Predict next month's revenue

"I have 6 months of sales. What's next quarter going to look like?"
const sales = [42000, 45000, 48000, 52000, 55000, 58000]; const forecast = await trendForecast(sales, 3); forecast.getForecast(); // [61000, 64000, 67000] forecast.direction; // "up" forecast.strength; // 0.99 (99% confidence)

๐Ÿ“Š Stock Trendlines

Add trend lines and moving averages to charts

"Is this stock going up or down? I need a trendline for my chart."
const prices = [150, 152, 149, 155, 158, 160]; // Fit trendline const model = await linearRegressionSimple(prices); model.slope; // 1.8 (growing $1.80/day) // Smooth with moving average const smooth = await ema(prices, 3);

๐Ÿ‹๏ธ Fitness Tracking

Predict goal completion date

"When will I reach my goal weight at this rate?"
const weights = [200, 198, 196, 194, 192]; // weekly const goal = 175; const model = await linearRegressionSimple(weights); const lossPerWeek = Math.abs(model.slope); // 2 lbs const weeksToGoal = (192 - goal) / lossPerWeek; // โ†’ 8.5 weeks to goal

๐ŸŒก๏ธ IoT Sensors

Smooth noisy sensor readings

"Temperature sensor jumps around. I need a stable reading."
// Noisy readings const raw = [22.1, 25.3, 21.8, 24.9, 23.2]; // Smoothed (removes noise) const smooth = await ema(raw, 3); // โ†’ [22.1, 23.7, 22.75, 23.82, 23.51] // Display last value display(smooth[smooth.length - 1]); // 23.5ยฐ

๐Ÿš€ Growth Analysis

Find doubling time and growth rate

"User base is growing. When will we hit 1 million?"
const months = [1, 2, 3, 4, 5, 6]; const users = [1000, 1500, 2200, 3300, 5000, 7500]; const model = await exponentialRegression(months, users); model.doublingTime(); // 1.4 months // Growth rate: ~50%/month

โšก Anomaly Detection

Find spikes and unusual values

"Alert me when server response time spikes."
const times = [50, 55, 48, 180, 52, 49, 150]; const spikes = await findPeaks(times); // โ†’ [3, 6] (indices of spikes) if (spikes.includes(times.length - 1)) { alert('Spike detected!'); }

๐Ÿ“š Learning Curves

Model diminishing returns

"Learning is fast at first, then slows. How do I model this?"
const hours = [1, 2, 5, 10, 20, 50, 100]; const skill = [10, 25, 45, 60, 75, 90, 98]; const model = await logarithmicRegression(hours, skill); // skill = 0.5 + 21.3 ร— ln(hours) // Hours needed for 95% skill? const needed = Math.exp((95 - model.a) / model.b);

๐Ÿ“ Curve Fitting

Fit parabolas and polynomials

"My data is curved, not straight. Ball trajectory, etc."
// Projectile motion const time = [0, 0.5, 1, 1.5, 2, 2.5]; const height = [0, 11, 20, 25, 26, 24]; const model = await polynomialRegression(time, height, { degree: 2 // quadratic }); // height = cโ‚€ + cโ‚ร—t + cโ‚‚ร—tยฒ

API Reference

๐Ÿ“ˆ Regression (Find Patterns)

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

ใ€ฐ๏ธ Smoothing (Remove Noise)

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

๐Ÿ”ฎ Forecasting (Predict Future)

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

๐Ÿ” Analysis (Understand Data)

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

Try It Live

Results

Enter data and click Analyze

Quick Start

// npm install micro-ml import { linearRegression, trendForecast, ema } from 'micro-ml'; // Fit a model const model = await linearRegression([1,2,3,4,5], [2,4,6,8,10]); model.slope; // 2 model.predict([6]); // [12] // Forecast future const forecast = await trendForecast([10,20,30,40,50], 3); forecast.getForecast(); // [60, 70, 80] // Smooth noisy data const smooth = await ema([10,15,12,18,14,20], 3);
View on GitHub