askesis

Machine learning basics: 50 cards on models, training and metrics

Machine learning flashcards: supervised vs unsupervised learning, overfitting, bias-variance, regularization, gradient descent, common models and metrics.

Data & AIBeginner50 cardsFree

Practice now

Study without an account

0 of 50 seen0 graduated
Supervised vs unsupervised learning

Scheduled with the default Askesis timings. Progress is saved in this browser.

All 50 cards

  1. 1
    Supervised vs unsupervised learning
    Supervised learning trains on labeled examples (inputs with known answers) to predict labels for new inputs; unsupervised learning finds structure, such as clusters, in unlabeled data
  2. 2
    Classification vs regression
    Classification predicts a category (spam or not spam); regression predicts a continuous number (a house price)
  3. 3
    Reinforcement learning
    An agent learns by taking actions in an environment and receiving rewards, aiming to maximize its total reward over time
    Used for game-playing agents, robotics, and fine-tuning language models from human feedback (RLHF).
  4. 4
    Features and labels
    Features are the input variables a model uses; the label (or target) is the value it learns to predict
    Predicting house prices: size and location are features, the sale price is the label.
  5. 5
    Parameters vs hyperparameters
    Parameters, such as weights, are learned from the data during training; hyperparameters (learning rate, tree depth, k in k-NN) are set before training and tuned on validation data
  6. 6
    Train, validation and test sets
    The training set fits the model, the validation set guides tuning and model selection, and the test set gives a final, unbiased estimate of performance on unseen data
    Common splits are 70/15/15 or 80/10/10; cross-validation can replace a fixed validation set.
  7. 7
    Why keep the test set untouched until the end?
    Every decision made by looking at test scores leaks information into the model, so the test score becomes optimistic and no longer predicts real-world performance
  8. 8
    Split data 80/20 in scikit-learn, keeping class proportions
    python
    from sklearn.model_selection import train_test_split
    
    X_train, X_test, y_train, y_test = train_test_split(
        X, y, test_size=0.2, stratify=y, random_state=42
    )
    stratify=y keeps the same class balance in both sets; random_state makes the split reproducible.
  9. 9
    Data leakage
    Information that wouldn’t be available at prediction time sneaks into training, so validation scores look far better than real performance
    Examples: fitting a scaler on the full dataset before splitting, a feature computed from the target, or random splits of time-series data that let the model see the future.
  10. 10
    Scale features without leaking validation data into training
    python
    from sklearn.pipeline import make_pipeline
    from sklearn.preprocessing import StandardScaler
    from sklearn.linear_model import LogisticRegression
    
    model = make_pipeline(StandardScaler(), LogisticRegression())
    model.fit(X_train, y_train)
    Inside a pipeline the scaler is fitted only on the training data, or on the training folds during cross-validation.
  11. 11
    Overfitting
    The model memorizes noise and quirks of the training data: training error is low but validation error is much higher
  12. 12
    Underfitting
    The model is too simple to capture the pattern: error is high on both the training and the validation data
  13. 13
    Training accuracy 99%, validation accuracy 72%. Diagnosis?
    Overfitting (high variance): the model fits the training data far better than new data
    Try more data, a simpler model, stronger regularization or early stopping.
  14. 14
    Bias vs variance
    Bias is error from overly simple assumptions (underfitting); variance is error from sensitivity to the particular training sample (overfitting). More complex models usually lower bias but raise variance
  15. 15
    Bias-variance decomposition of expected squared error
    E[(y−f^(x))2]=Bias[f^(x)]2+Var[f^(x)]+σ2\mathbb{E}\big[(y - \hat{f}(x))^2\big] = \mathrm{Bias}\big[\hat{f}(x)\big]^2 + \mathrm{Var}\big[\hat{f}(x)\big] + \sigma^2
    σ2\sigma^2 is irreducible noise: no model can remove it.
  16. 16
    Common ways to reduce overfitting
    Get more data, simplify the model, add regularization, stop training early, use dropout, augment the data, or drop noisy features
    Early stopping halts training when the validation loss stops improving.
  17. 17
    Regularization
    Adding a penalty for model complexity, usually large weights, to the loss so the model is discouraged from fitting noise
  18. 18
    L1 vs L2 regularization
    L1 (lasso) adds λ∑i∣wi∣\lambda\sum_i |w_i| and drives some weights to exactly zero; L2 (ridge) adds λ∑iwi2\lambda\sum_i w_i^2 and shrinks all weights smoothly
    L1 doubles as feature selection. Elastic net combines both penalties.
  19. 19
    What happens as you increase the regularization strength?
    The model gets simpler: variance falls and bias rises. Too much regularization underfits
    In scikit-learn’s LogisticRegression and SVMs, C is the inverse of the strength: a smaller C means stronger regularization.
  20. 20
    Dropout
    During training, randomly zeroes a fraction of a layer’s outputs on each step so the network can’t rely on any single neuron; it is switched off at inference
    Typical rates are 0.1 to 0.5.
  21. 21
    Loss function
    A function that measures how far predictions are from the true values; training adjusts the parameters to minimize it
    Mean squared error for regression, cross-entropy (log loss) for classification.
  22. 22
    Mean squared error (MSE)
    MSE=1n∑i=1n(yi−y^i)2\mathrm{MSE} = \dfrac{1}{n}\displaystyle\sum_{i=1}^{n} (y_i - \hat{y}_i)^2
  23. 23
    Binary cross-entropy (log loss)
    L=−1n∑i=1n[yilog⁡p^i+(1−yi)log⁡(1−p^i)]L = -\dfrac{1}{n}\displaystyle\sum_{i=1}^{n} \big[y_i \log \hat{p}_i + (1 - y_i)\log(1 - \hat{p}_i)\big]
    It punishes confident wrong predictions heavily.
  24. 24
    Gradient descent update rule
    θ←θ−η ∇θL(θ)\theta \leftarrow \theta - \eta\,\nabla_\theta L(\theta)
    Each step moves the parameters θ\theta against the gradient of the loss; η\eta is the learning rate.
  25. 25
    Learning rate too high vs too low
    Too high: updates overshoot, so the loss oscillates or diverges. Too low: training converges very slowly or stalls
  26. 26
    Batch vs stochastic vs mini-batch gradient descent
    Batch uses the whole dataset for each update, stochastic (SGD) a single example, and mini-batch a small batch such as 32 to 256 examples, the usual compromise
    One epoch is one full pass over the training data.
  27. 27
    Linear regression
    Predicts a number as a weighted sum of the features plus a bias, y^=w⊤x+b\hat{y} = w^\top x + b, fitted by minimizing squared error
  28. 28
    Logistic regression
    A classifier that passes a linear score through the sigmoid σ(z)=11+e−z\sigma(z) = \dfrac{1}{1 + e^{-z}} to get a probability between 0 and 1
    Despite the name, it is used for classification.
  29. 29
    Decision tree
    Splits the data with a sequence of if/else questions on feature values, choosing the splits that best separate the targets
    Easy to interpret, but deep trees overfit; limit max_depth or prune them.
  30. 30
    Random forest
    An ensemble of decision trees, each trained on a bootstrap sample of the data with a random subset of features considered at each split; predictions are averaged or voted
    This is bagging: averaging many independently trained trees reduces variance.
  31. 31
    Gradient boosting
    Builds trees one after another, each fitting the remaining errors (the loss gradients) of the ensemble so far
    Boosting mainly reduces bias. XGBoost, LightGBM and CatBoost are popular implementations and often win on tabular data.
  32. 32
    k-nearest neighbors (k-NN)
    Predicts from the k closest training examples: a majority vote for classification, an average for regression
    There is no real training step, but prediction is slow on large datasets and features must be scaled.
  33. 33
    Support vector machine (SVM)
    Finds the decision boundary with the widest margin between the classes; kernels such as RBF allow non-linear boundaries
  34. 34
    k-means clustering
    Unsupervised: picks k centroids, then repeatedly assigns each point to its nearest centroid and moves each centroid to the mean of its points
    You choose k yourself, often with the elbow method or the silhouette score.
  35. 35
    Principal component analysis (PCA)
    Unsupervised dimensionality reduction that projects the data onto the orthogonal directions of greatest variance
    Used to compress features, speed up training and plot high-dimensional data in 2D.
  36. 36
    Which models need feature scaling?
    Distance- and gradient-based ones: k-NN, k-means, SVMs, neural networks and regularized linear models. Tree-based models don’t need it
    Standardization: z=(x−μ)/σz = (x - \mu)/\sigma, with μ\mu and σ\sigma computed on the training set only.
  37. 37
    One-hot encoding
    Turns a categorical feature into one binary column per category, so models don’t read a false order into category codes
    A color column with red, green and blue becomes is_red, is_green and is_blue.
  38. 38
    Confusion matrix
    A table of predicted against actual classes, giving the counts of true positives, false positives, true negatives and false negatives
  39. 39
    Why can accuracy mislead?
    With imbalanced classes a useless model scores high: if 99% of transactions are legitimate, always predicting “legitimate” is 99% accurate and catches no fraud
  40. 40
    Precision
    TPTP+FP\dfrac{TP}{TP + FP}: of the items predicted positive, the share that really are positive
  41. 41
    Recall (sensitivity)
    TPTP+FN\dfrac{TP}{TP + FN}: of the actual positives, the share the model found
    Also called the true positive rate.
  42. 42
    F1 score
    The harmonic mean of precision and recall: F1=2PRP+RF_1 = \dfrac{2PR}{P + R}
    It is high only when both precision and recall are high.
  43. 43
    Cancer screening vs spam filter: favor precision or recall?
    Screening favors recall, because a missed case is costly; a spam filter favors precision, because losing a real email to the spam folder is costly
    Raising the decision threshold usually increases precision and lowers recall.
  44. 44
    ROC curve and ROC-AUC
    The ROC curve plots the true positive rate against the false positive rate across all thresholds; AUC is the area under it, where 0.5 means random guessing and 1.0 a perfect ranking
    AUC equals the probability that a random positive is ranked above a random negative. On heavily imbalanced data, the precision-recall curve is often more informative.
  45. 45
    k-fold cross-validation
    Split the data into k folds, train on k − 1 of them and validate on the remaining one, rotate k times, then average the scores
    python
    from sklearn.model_selection import cross_val_score
    
    scores = cross_val_score(model, X, y, cv=5, scoring="f1")
  46. 46
    MAE vs RMSE
    Both measure regression error in the target’s units; RMSE squares errors before averaging, so it penalizes large errors more than MAE does
  47. 47
    What does a single artificial neuron compute?
    A weighted sum of its inputs plus a bias, passed through an activation function: a=f(w⊤x+b)a = f(w^\top x + b)
  48. 48
    Why do neural networks need non-linear activation functions?
    Without them, any stack of layers collapses into a single linear function, so extra layers add nothing
    ReLU, max⁡(0,x)\max(0, x), is the usual default for hidden layers.
  49. 49
    Backpropagation
    Computes the gradient of the loss with respect to every weight by applying the chain rule backward from the output layer; an optimizer such as SGD or Adam then updates the weights
  50. 50
    Softmax
    Turns a vector of scores (logits) into probabilities that sum to 1: softmax(z)i=ezi∑jezj\mathrm{softmax}(z)_i = \dfrac{e^{z_i}}{\sum_j e^{z_j}}
    Used in the output layer of multi-class classifiers.

Frequently asked questions

Do I need a lot of math for this deck?

Basic algebra is enough for most cards. A few formulas, such as the gradient descent update and log loss, are shown in LaTeX next to a plain-language explanation.

Does it cover deep learning?

Only the basics: neurons, activation functions, backpropagation, softmax and dropout. The focus is on concepts that apply to every model, from linear regression to neural networks.

Which library do the code examples use?

scikit-learn, the standard Python library for classic machine learning. The ideas carry over to any framework.

Is it useful for data science interviews?

Yes. Overfitting, the bias-variance tradeoff, precision vs recall, ROC-AUC and cross-validation are among the most common interview questions.