My AI Journey · Machine Learning Foundations

How machines learn from data

A complete map of features, feature engineering, scaling, learning paradigms, model families, training algorithms and inference—plus how the pieces connect.

1. The big picture

๐Ÿ—‚๏ธ

Raw data

facts, measurements, text, images

โ†“
๐Ÿงฉ

Features

signals the model can use

โ†“
๐Ÿ‹๏ธ

Training

learn parameters or structure from examples

โ†“
๐Ÿ“ฆ

Trained model

the learned parameters, frozen and saved

โ†“
๐ŸŽฏ

Inference

predict from new, unseen input

2. What is a feature?

size_m² | bedrooms | age | city | price 90 | 3 | 12 | Berlin | €550k 60 | 1 | 35 | Leipzig | €220k FEATURES ↑ TARGET ↑

One usable input signal

A feature is usually one dataset column: numerical (size_m²), categorical (city), Boolean, text-derived, image-derived, or engineered from other columns. The target is the answer a supervised model learns to predict—here, price. A row of features plus its target is one training example.

3. Feature engineering and scaling

Feature engineering

Turn raw facts into clearer signals

birth date→age debt ÷ income→debt ratio timestamp→rush hour?

The model sees exactly what you feed it. A derived feature that states the pattern directly (age instead of birth date) makes the pattern learnable with less data and a simpler model.

Feature scaling

Put numeric features on comparable scales

standardize: x′ = (x − mean) / standard deviation min–max: x′ = (x − min) / (max − min)

Needs scaling: KNN, K-means, SVM, neural networks, PCA, regularized regression — anything built on distances, dot products or shared penalty strength.
Usually doesn’t: decision trees, random forests, gradient boosting — trees split on thresholds one feature at a time, so a feature’s scale never mixes with another’s.

Avoid data leakage: fit feature engineering and scalers on training data only; apply the fitted transformations, unchanged, to validation, test, and future data. If the scaler has seen the test set’s mean, your evaluation is quietly cheating.

4. Main learning paradigms

๐Ÿท๏ธ Supervised learning

Inputs come with known targets. The model learns to predict a number (regression) or a class (classification). Output: a predictor for new rows.

linear regressionpolynomial regression ridge / lassologistic regression KNNdecision treerandom forest gradient boostingSVMNaive Bayes neural networks

From observations to learned coefficients

Linear regression is a small, concrete example of what “training” means. For every observed feature value xi and target yi, the model predicts ลทi = wxi + b. The parameters w (slope) and b (intercept) do not come from the data ready-made: training chooses them.

prediction: ลทi = wxi + b residual: ei = yi − ลทi objective: minimize Σi ei2 = Σi [yi − (wxi + b)]2
A three-step diagram: observed input-target pairs, predictions from y-hat equals wx plus b with residuals, and minimizing the sum of squared residuals.
Least squares makes larger misses matter more by squaring them. A closed-form solver can find the best coefficients directly; gradient descent reaches the same goal by repeatedly adjusting them to reduce this objective.
Training versus evaluation: squared error here helps select w and b from training examples. After the model is frozen, metrics such as MSE compare y_true and y_pred on held-out data to judge how well that learned line generalizes.

๐Ÿงญ Unsupervised learning

Inputs come without targets. The model finds structure: groups, directions of variation, density, outliers. Output: cluster assignments, compressed representations, anomaly scores.

K-meanshierarchical clustering DBSCANPCAt-SNE / UMAP autoencodersisolation forest

๐ŸŒ— Semi-supervised

A few labeled examples + many unlabeled ones. Labels are expensive; structure in the unlabeled mass helps place the boundary.

๐Ÿชž Self-supervised

The data labels itself: hide a part, predict it (next word, masked patch). How LLMs pretrain—supervised machinery, no human labels.

๐Ÿ•น๏ธ Reinforcement

An agent acts, the environment scores it with rewards. Learns a policy that maximizes long-run reward (games, robotics, RLHF).

โœ‹ Active

The model chooses which examples a human should label next—the ones it is most unsure about. Fewer labels, same accuracy.

๐ŸŒŠ Online

Learns from a stream, one example (or mini-batch) at a time; adapts as the world drifts. Contrast: batch training on a frozen dataset.

๐ŸŽ’ Transfer

Start from a model trained on a big general task, fine-tune on your small specific one. Reuse of learned representations.

๐Ÿค Federated

Training runs where the data lives (phones, hospitals); only weight updates travel, raw data never leaves the device.

5. Model family vs. training algorithm vs. trained model

Model family
the shape of hypothesis you allow: “a line”, “a depth-5 tree”, “a 3-layer network”. Defines what is learnable.
Training algorithm
the procedure that picks one member of the family using data: gradient descent, tree splitting, Lloyd’s iterations.
Trained model
the chosen member—concrete parameter values (weights, split points, centroids), frozen after training. The artifact you save.
Inference algorithm
how the trained model answers a query: a matmul forward pass, a walk from root to leaf, nearest-centroid lookup.
Computational procedure
how the math actually runs on hardware: vectorized loops, GPU kernels, distributed workers. Same model, many possible procedures.

Example, end to end: family = linear functions · training = least squares / gradient descent · trained model = the coefficients · inference = one dot product · procedure = a BLAS call on a CPU or GPU.

6. Training vs. inference, model by model

ModelTraining does…Inference does…
Linear regressionfind coefficients minimizing squared errorone weighted sum per prediction
Logistic regressionfind coefficients minimizing cross-entropyweighted sum → sigmoid → probability
Decision treegreedily choose splits that purify the leaveswalk root→leaf following the input’s answers
Random foresttrain many trees on bootstrapped rows / random feature subsetsrun every tree, average (or vote)
Neural networkforward + loss + backprop + optimizer step, millions of timesforward pass only—matmuls with frozen weights
K-meansalternate: assign points to nearest centroid / move centroids to the meanassign a new point to its nearest centroid
PCAfind the directions of greatest variance (eigenvectors)project a new point onto those directions
KNNnothing—just store the data (“lazy learner”)find the K nearest stored points, vote / average
DBSCANgrow clusters from density-connected points; flag outliersno native predict; typically re-run or assign to nearest cluster

Notice the asymmetry: training is iterative and expensive; inference is a single cheap pass—except KNN, which flips the trade (free training, costly queries).

7. Spotlight: polynomial regression

ŷ = w₀ + w₁x + w₂x² + w₃x³ + … + wₖxᵍ

Still supervised (there is a target) and—surprisingly—still linear regression: the function is linear in the weights w. The curve comes from the features, not the model.

1
Engineer features
from x build x², x³, …
→
2
Linear regression
on the expanded columns
→
3
Curved fit
a “line” in a bigger space

That is why it is often described as polynomial feature engineering + plain linear regression— and why scikit-learn implements it literally as PolynomialFeatures → LinearRegression.

8. The two K’s are different K’s

K in KNN = neighbors consulted

Supervised. To classify a new point, look at its K nearest labeled points and let them vote. K=1: trust the single closest example. K=15: smoother, more democratic boundary.

K in K-means = clusters requested

Unsupervised. You declare up front “organize this data into K groups”; the algorithm places K centroids and carves the data around them. K is the number of buckets, not neighbors.

Same letter, unrelated meanings: one sizes a jury, the other counts buckets.

9. Unsupervised models can build features for supervised ones

1
K-means / PCA
fit on training rows
→
2
New columns
cluster id · distance to centroid · top components
→
3
Supervised model
trains on original + new features

A customer’s cluster membership (“segment 3”) or a row’s first few principal components are often stronger signals than the raw columns they summarize. The unsupervised stage is acting as automated feature engineering.

Same leakage rule as scalers: fit the K-means / PCA stage on training data only, then apply the frozen transformation to validation and test rows. An unsupervised step that has “seen” the test set leaks information exactly like a scaler would.

10. The modern AI workflow (how LLMs are actually built)

1
Self-supervised pretraining
predict the next token on internet-scale text; no human labels
→
2
Supervised fine-tuning
small, curated set of prompt→good-answer pairs
→
3
Preference / reward learning
humans rank answers; RLHF / DPO shape behavior
→
4
Inference
frozen weights serve millions of forward passes

Every paradigm from section 4 shows up in one pipeline: self-supervised pretraining does the heavy lifting, supervised fine-tuning aims it, reinforcement-style preference learning polishes it, and transfer learning is the whole premise—each stage starts from the previous stage’s weights. Inference is then pure forward passes: the training machinery (loss, gradients, optimizer) is gone.