A 34-minute working session on the ideas under every ML system: how a model learns from data instead of hand-written rules, the main families of algorithms, how you train and evaluate one — and the honest question of when ML is the wrong tool.
In ordinary programming you write the rules and the computer follows them. Machine learning flips that around: you feed it examples — inputs and the answers you want — and it figures out the rule that connects them. The output is a model you can run on new, unseen inputs.
Same pieces, reversed arrows: classic code consumes rules; ML produces them from data plus answers.
// hand-written rules — endless edge cases function isSpam(email: string): boolean { if (email.includes("free money")) return true if ((email.match(/!/g) ?? []).length > 5) return true return false // spammers adapt → you patch forever }
// learn the pattern from labeled examples import { LogisticRegression } from 'ml-logistic-regression' const model = new LogisticRegression() model.train(xTrain, yTrain) // X = features, y = spam? model.predict(newEmail) // generalizes to unseen spam
ML is not a default. It adds data pipelines, training cost, drift, and opacity. Reach for plain rules or a lookup table when:
if.Rule of thumb reach for ML when the rules are too many, too fuzzy, or always changing to write by hand — recognizing spam, ranking results, forecasting demand.
Almost everything in classical ML falls into one of three setups, defined by what kind of feedback the model gets while learning: full answers, no answers, or rewards.
Every training example comes with the correct output (the label). The model learns the mapping features → label, then predicts labels for new inputs.
You hand the model raw data with no answers and ask it to find structure on its own — natural groups, or a simpler representation.
An agent takes actions in an environment and gets rewards or penalties. Over many tries it learns a policy that maximizes long-term reward.
Supervised flow: labeled examples train the model once; afterward it labels brand-new inputs.
Most production ML you will meet is supervised — so the rest of this deck leans there.
The task is what you are predicting; the algorithm is how. Click through the three core tasks, then skim the cheat-sheet of algorithms that earn their keep on everyday tabular data.
import { SimpleLinearRegression } from 'ml-regression' const model = new SimpleLinearRegression(xTrain, yTrain) model.predict(xNew) // → a number: price, temperature, demand…
Fit a line (or curve) through the data; read off a number for any new input.
import { RandomForestClassifier } from 'ml-random-forest' const clf = new RandomForestClassifier({ nEstimators: 300 }) clf.train(xTrain, yTrain) clf.predict(xNew) // → a label: spam / not-spam, fraud / ok
Learn a boundary that separates the classes; new points are labeled by which side they land on.
import { KMeans } from 'ml-kmeans' const result = KMeans(X, 4) // no labels! result.clusters // → which group each point landed in
No labels given — the algorithm groups points by similarity and you interpret the groups.
Fits a straight-line relationship. Fast, interpretable baseline for predicting a number.
Despite the name, a classifier: outputs a probability for a class. The default first model.
A flowchart of yes/no splits. Human-readable but prone to memorizing the training set.
Many trees on random subsets, votes averaged (bagging). Strong, forgiving default.
Trees built in sequence, each fixing the last one's errors. XGBoost / LightGBM dominate tabular contests.
Predict by looking at the k nearest known examples. No real training — it just remembers.
Unsupervised: partitions points into k clusters around moving centers.
Finds the widest-margin boundary between classes; kernels handle non-linear splits.
These shine on structured / tabular data — rows and columns. When the input is images, audio, or free text, hand-made features break down and you move to Deep Learning & Neural Networks, where the model learns its own features.
Two ideas do most of the work: turning raw data into good features, and splitting your data so you measure the model on examples it never trained on. Skip the split and you will fool yourself every time.
The cardinal sin is data leakage: letting any test information sneak into training. The test score then lies, and production disappoints.
A typical 60 / 20 / 20 split. Exact ratios vary; the principle — never test on what you trained on — does not.
// split 80 / 20 const idx = Math.floor(X.length * 0.8) const [xTrain, xTest] = [X.slice(0, idx), X.slice(idx)] const [yTrain, yTest] = [y.slice(0, idx), y.slice(idx)] // 5-fold cross-validation const k = 5, sz = Math.floor(xTrain.length / k) const scores = Array.from({ length: k }, (_, i) => evaluate(model, xTrain.slice(i*sz, (i+1)*sz)) ) scores.reduce((a,b) => a+b, 0) / k // avg score across 5 folds
Cross-validation rotates the validation fold so every row is tested once — a steadier score than a single split.
Every model lives between two failure modes. Learn too little and it misses the pattern; learn too much and it memorizes noise. Managing that tension — the bias-variance trade-off — is the heart of practical ML.
Same points, three models. The straight line misses the trend; the wiggly line chases every dot; the smooth curve generalizes.
Bias is error from being too simple; variance is error from being too sensitive. Total error bottoms out in between.
Pick the metric that matches the cost of being wrong. On a dataset that is 99% "not fraud", a model that always says "not fraud" scores 99% accuracy and catches zero fraud. The confusion matrix is where you start.
Four outcomes. Which one hurts more — a false alarm or a miss — decides whether you optimize precision or recall.
(TP + TN) / everything. Fine when classes are balanced — misleading when one class is rare (fraud, disease).
TP / (TP + FP). Optimize when a false alarm is costly — e.g. blocking a legit payment.
TP / (TP + FN). Optimize when a miss is costly — e.g. failing to detect cancer or fraud.
The harmonic mean of precision and recall — one number when you need both to be decent and the classes are imbalanced.
const preds = model.predict(xTest) // compute TP / FP / FN / TN per class const cm = confusionMatrix(yTest, preds) const report = classificationReport(yTest, preds) console.log(cm, report) // precision, recall, F1 per class — one call
The discipline is the same: choose the metric before you train, tied to what a mistake actually costs the business.
A small, stable set of libraries covers almost everything. Then the harder call: ML is powerful, but it is also a liability. Here is the honest balance sheet.
The standard toolkit: regression, classification, clustering, splits, metrics — one clean API.
Specialized boosted-tree libraries that win most tabular benchmarks and Kaggle competitions.
The dominant framework for neural networks — flexible, Pythonic, behind most modern research and LLMs.
The other major deep-learning stack; Keras gives a friendly high-level API, with strong mobile / serving tooling.
Five quick questions on what ML is, the learning setups, training, the bias-variance trade-off, and metrics — instant feedback, no sign-in.
Navigate with ← → or scroll · back to library