Skip to content

ML Basics

Glossary

118 terms from ML Basics, in plain words, each with the chapter that teaches it.

A

Accuracy
The share of predictions that are right. It can mislead when one class is rare: predicting "nobody cancels" at Kettle & Crane is right about 90% of the time.
Average precision
A single number that summarizes the precision-recall curve. A random model scores about the positive rate, roughly 0.10 for the cancel data, so it suits very rare positives.

B

Baseline
The score of a simple model that learns nothing useful, such as always predicting the most common class. A real model must beat it to be worth using.
best_estimator_
Attributes of a fitted grid or randomized search. They hold the winning pipeline refit on all training rows, the winning settings, and their mean CV score.
Bootstrap sample
Rows drawn at random with repeats, as many as the training set has. Each tree in a random forest trains on its own bootstrap sample.
Break-even threshold
The chance of canceling at which a call's expected saving equals its cost: $10 ÷ $36 ≈ 0.278. If probabilities are calibrated, flag everyone at or above it.

C

Calibrated
Describes a model whose predicted probabilities match reality: of subscribers given 30%, about 30% really cancel. Priya's churn model is calibrated, so its scores can be read as honest chances.
calibration_curve
A function that sorts rows into groups by predicted risk and returns each group's real rate and average prediction, to check whether probabilities are honest.
category dtype
A pandas column type with a fixed set of possible values. Histogram gradient boosting can use these columns directly, without one-hot encoding.
class
One of the categories a classifier predicts, such as canceled or stayed.
class_weight
A model setting that makes rare-class rows count more during training. It distorts predicted probabilities and rarely improves ranking, so choosing a threshold is usually clearer.
Classification
Supervised learning where the target is a category, such as whether a Kettle & Crane subscriber will cancel (yes or no).
classification_report
A scikit-learn function that prints precision, recall, F1 and support for each class, plus macro and weighted averages.
Clustering
Unsupervised learning that groups similar rows without any labels, for example finding types of subscriber.
Coefficient
The weight a linear model multiplies a feature by. In Sam's café model, each extra seat adds about 0.46 lb because its coefficient is 0.46.
ColumnTransformer
A scikit-learn tool that sends different groups of columns through different preparation steps and glues the results side by side. Unlisted columns are dropped unless you set remainder="passthrough", which keeps them unchanged.
Confusion matrix
A table counting the four outcomes of a classifier: true and false positives and true and false negatives. Rows are the truth and columns are the predictions.
ConvergenceWarning
A warning that a model's step-by-step fitting stopped before settling. Scale the features or raise max_iter, which defaults to 100 for logistic regression.
Cross-validation (k-fold)
Splits training rows into k folds, then trains and scores k times so each fold is the test part once. You report the mean score and its spread.
cross_val_predict
A scikit-learn function that returns a prediction for every training row from a model that never saw that row. It fits a copy of the model on all folds but one, predicts the held-out fold, and repeats, so the predictions can be used to choose a threshold without touching the test set.
cross_val_score
Cross-validates a model and returns one score per fold, using the metric named in scoring=.
cross_validate
Like cross_val_score but returns a dict with several metrics, timings and, optionally, training scores, which helps you spot overfitting.

D

Data leakage
Information getting into training that won't be available when you really predict. It makes a model look great in testing and fail in use.
Decision tree
A model that predicts by asking a series of yes/no questions about the features, like a flowchart. Each final box is a leaf with a cancel rate.
Distance
How far apart two rows are, treating each row as a point and measuring the straight-line distance between feature values. k-nearest neighbors uses it to find similar subscribers.
DummyClassifier
A scikit-learn model that ignores the features and makes simple guesses, such as the most common class or the mean. It gives the baseline a real model must beat.

E

Early stopping
Holding back part of the training data and stopping boosting once the score on it hasn't improved for a set number of rounds.
Ensemble
A model that combines many models, such as the hundreds of trees in a random forest.
Estimator
Any scikit-learn object you create with settings and then fit to data. Models and pipelines are estimators.
Example
One row of past data used for training or testing, such as one subscriber with a known outcome.

F

F1
One number that combines precision and recall as their harmonic mean. It stays low if either one is low.
False positive / negative
A false positive is a subscriber flagged but who really stayed (a wasted call). A false negative is a canceler the model didn't flag.
False positive rate
The share of real negatives that were flagged: FP ÷ (FP + TN). It is the horizontal axis of the ROC curve.
Feature
An input column the model uses to predict, such as tenure, plan or skipped deliveries.
Feedback loop
When a model's predictions change the data it later learns from. Subscribers Priya calls and keeps show up as "stayed", which can teach a retrained model the wrong lesson.
fit
The scikit-learn method that learns from data. Transformers then use transform to change any data the same way, and fit_transform does both at once.
Fold
One of the k equal parts the rows are cut into for cross-validation.

G

Google Colab
A free service that runs Python notebooks in your browser, so you don't have to install anything.
Gradient boosting
Builds small trees one after another, each trained to correct the errors left so far, then adds them up. Often the most accurate model for tables of data.
GridSearchCV
Tries every combination of the hyperparameter values you list, cross-validates each, and keeps the best. It then refits the winner on all training rows.
Group leakage
Leakage when rows from the same group, such as one café's weeks, land on both sides of a split. Keep each group on one side with GroupShuffleSplit or GroupKFold.
GroupKFold
A cross-validation splitter that keeps all rows of one group, such as one café's weeks, in the same fold. Pass groups= when you use it.

H

Harmonic mean
An average of rates that stays low if either one is low. F1 uses it to combine precision and recall.
HistGradientBoostingClassifier
scikit-learn's fast gradient boosting model. It first sorts each feature into at most 255 bins, accepts missing values, and can use category columns directly.
Hyperparameter
A setting you choose before fitting, such as n_neighbors or max_depth. Parameters, by contrast, are what the model learns.

I

Imbalanced classes
When one class is much rarer than the other. Only about 10% of Kettle & Crane subscribers cancel, so accuracy hides almost everything.
Imputation
Filling missing values with an estimate, such as the median learned from the training rows.
Interaction
When one feature's effect depends on another. In the café data, temperature matters about twice as much for cafés with a drive-through, and trees can find this on their own.
Intercept
A linear model's starting value, the prediction when every feature is zero.

J

joblib
The library, installed with scikit-learn, used to save a fitted model to a file with dump and read it back with load.

K

k-nearest neighbors
A model that predicts for a new row by finding the k most similar training rows and letting them vote. Training just stores the examples.
KFold
Splitter objects that control how cross-validation folds are cut. Use StratifiedKFold for classification and TimeSeriesSplit for time-ordered rows, which always trains on the past and tests on the future.

L

Label
The known answer for a training example, for instance whether a subscriber canceled in September.
Leaf
A final box of a decision tree. It holds the training rows that ended up there, and the prediction is their cancel rate.
Learning curve
A plot of training and validation scores against the number of training rows. It shows whether more data would help.
Learning rate
In gradient boosting, how much of each new tree's correction is added. Smaller steps learn more carefully but need more trees.
Linear regression
Predicts a number as a weighted sum of the features plus an intercept, as Sam does to forecast each café's weekly order.
Log-odds
The logarithm of the odds p ÷ (1 − p). It is the scale of logistic regression's weighted sum, where each step of 1 multiplies the odds by about 2.7.
Logistic regression
A classifier that computes a weighted sum and squeezes it through an S-shaped curve so the result is a probability between 0 and 1. Despite its name, it classifies.
loguniform
Range generators from scipy.stats for randomized search. randint draws whole numbers; loguniform draws decimals spread evenly on a log scale.

M

Machine learning
Building models that learn patterns from past examples with known answers, instead of writing the rules by hand.
MAE
Mean absolute error: the average size of the errors, in the target's units. A café MAE of 4.5 means predictions are typically off by about 4.5 lb.
make_pipeline
Chains steps and a model into a pipeline, naming each step after its lower-case class (such as standardscaler). Use named_steps to reach a step.
max_depth
Hyperparameters that rein in trees. max_depth is the most questions in a row; min_samples_leaf is the fewest training rows a leaf may hold; max_leaf_nodes caps the leaves per tree.
max_iter
In logistic regression, the maximum number of fitting steps (default 100). In histogram gradient boosting, the number of trees (rounds) to build.
Model
A function learned from data that takes the facts about a new row, such as a subscriber, and returns a prediction.
Model card
A short document describing a model's purpose, data, performance, limits and owner for the people who will use or review it.

N

n_estimators
The number of trees in a random forest. More trees mostly make results steadier rather than more accurate.
NumPy array
A grid of numbers that works much like a DataFrame without labels. scikit-learn returns predictions as arrays, and array[:, 1] means every row, column 1.

O

One-hot encoding
Turns a category column into one 0/1 column per category, so "plan" becomes plan_weekly, plan_biweekly and plan_monthly without implying an order. With handle_unknown="ignore", a category never seen in training becomes all zeros instead of an error.
Out-of-fold prediction
A prediction for a row made by a model that was not trained on that row, because the row was in the fold held out during cross-validation. These predictions give an honest estimate of how the model behaves on unseen data, so they can be used to choose a threshold without using the test set.
Overfitting
Learning the training data's noise instead of the general pattern. The training score is far above the validation score.

P

Parameter
A value the model learns during fitting, such as a coefficient. Names ending in an underscore, like mean_, are things learned in fit.
parse_dates
A read_csv option that turns date text into real dates so you can compare them, for example to split weeks by a cutoff.
Permutation importance
Shuffles one column at a time on held-out rows and measures how much the score drops. A big drop means the model relied on that column.
Pickle
Python's format for saving objects, used by joblib. Loading a pickle can run arbitrary code, so only load files you trust.
Pipeline
A chain of preparation steps and a model that acts as one estimator. It fits every step on training data only, so preparation can't leak.
Positive class
The class you are looking for, here "canceled". It is not meant as a good thing.
Precision
TP ÷ (TP + FP): of the subscribers flagged, the share that really canceled. It tells Priya how many of her calls are worth making.
Precision-recall curve
A plot of precision against recall at every threshold. It shows the cost of wasted flags that ROC AUC can hide when positives are rare.
Predicted probability
The model's estimated chance of each class, one column per class. predict_proba returns them, and predict picks the class with the higher one.
Preprocessing leakage
Leakage from fitting preparation steps, such as filling gaps with the average, on rows that include test rows. Putting them in a pipeline prevents it.
Proxy
A feature that stands in for another, often sensitive, one. Zip code can track income or race, so leaving race out doesn't keep its effect out.

R

Random forest
Hundreds of varied decision trees whose predictions are averaged. It is more accurate and stable than one tree.
random_state
A setting that fixes randomness, such as the shuffle in a split, so you get identical results every run. Any whole number works.
RandomizedSearchCV
Tries a fixed number of random hyperparameter combinations drawn from ranges you give, cross-validating each. It is usually as good as a full grid in less time.
Recall (true positive rate)
TP ÷ (TP + FN): of the subscribers who really canceled, the share the model flagged.
Regression
Supervised learning where the target is a number, such as how many pounds a café will order next week.
Regularization
A penalty on large coefficients that keeps a model simpler and guards against overfitting. In logistic regression, C controls it, and smaller C means more regularization.
Residual (error)
The true value minus the prediction for one row.
RMSE
Root mean squared error: square the errors, average them, take the square root. Like MAE, but big misses count extra.
ROC curve, ROC AUC
The ROC curve plots true positive rate against false positive rate at every threshold. Its area (AUC) is the chance a random canceler outranks a random stayer: 0.5 is guessing and 1.0 is perfect.
R²
The share of variation explained, compared with always predicting the mean. 1 is perfect, 0 is no better than the mean, and below 0 is worse.

S

scikit-learn (sklearn)
Python's main free, open-source machine learning library, imported as sklearn.
SciPy
A math library that scikit-learn builds on, installed alongside it.
SimpleImputer
A transformer that fills gaps with the mean, median, most frequent value or a constant, learned from training rows. With add_indicator=True it also adds a 0/1 column marking which rows had a gap.
skops
A library that loads saved models without running arbitrary code, suggested for files from outside sources.
Sparse matrix
A memory-saving table format that stores only the non-zero values. OneHotEncoder returns one by default; sparse_output=False gives an ordinary array.
Standardizing
Rescaling each column to mean 0 and standard deviation 1 (z-scores), so no column dominates just because of its units. StandardScaler does it.
Step-parameter names
To set a hyperparameter of a step inside a pipeline, write the step's name, two underscores, then the setting, as in histgradientboostingclassifier__max_depth.
Stratified
Keeping class shares equal across splits or folds, so each part has about 10% cancelers. In train_test_split you pass stratify=y.
Supervised learning
Learning from labeled examples, as if a teacher had marked the answers. Classification and regression are its two kinds.
Support
In a classification report, the number of true rows of each class.

T

Target
The thing the model predicts, such as whether a subscriber canceled. By convention it is stored in y.
Target leakage
A feature that is a consequence of the target rather than a clue to it. The exit survey is sent only after someone cancels, so it gives the answer away.
Test set
Rows held back for one final, honest check at the very end. Changing the model because of its test score makes the test set stop being honest.
Threshold
The probability at or above which a row is flagged. 0.5 is the default but only a choice. Lowering it raises recall and lowers precision, and it should be set by cost.
Tie (within the fold spread)
When two models' CV scores differ by less than their fold-to-fold spread, treat them as tied and prefer the simpler one.
Time-based split
For data collected over time, train on earlier rows and test on later ones, instead of shuffling. A random split would let the model learn from the future.
train_test_split
A scikit-learn function that shuffles rows and returns X_train, X_test, y_train and y_test. test_size sets the held-back share.
Training (fitting)
Finding the patterns in past examples, that is, learning a model's parameters from data.
Training set
The rows the model learns from.
Transformer
An object that learns something from training data with fit, then changes any data the same way with transform. Scalers, encoders and imputers are transformers.
True positive / negative
A true positive is a subscriber flagged who really canceled. A true negative is one not flagged who really stayed.

U

Underfitting
Being too simple to capture the pattern. Training and validation scores are both low and close together.
Unsupervised learning
Finding structure in data, such as groups, without any labels.

V

Validation curve
A plot of training and CV scores across values of one hyperparameter. It shows where the model underfits, where it overfits and where the sweet spot is.
Validation set
Rows used to make choices, such as which model or which k, so the test set stays untouched for the final check.