Choose your learning setup

Palette: standard

Progress

Start with the first concept.

Learn the core ideas

Explore the graphs

Every graph includes a nearby text fallback with the same lesson.

10-question knowledge check

Open complete static explanations and answer review

Complete static learning reference

This reference remains available when scripts or browser storage are unavailable.

Concepts

Match the classifier to the target structure

Classification predicts categorical targets or probabilities over categories. Binary tasks have two outcomes, multiclass tasks choose among more than two classes, multilabel tasks can assign several labels to one observation, and ordinal tasks use ordered classes whose gaps are not necessarily equal.

How to interpret it: Identify whether one or several labels can apply and whether label order matters before choosing modeling and evaluation methods. An ordinal target preserves order without turning the levels into an ordinary continuous measurement.

Common mistakes
  • Treating a multilabel task as multiclass even though several labels can be correct at once.
  • Treating ordered labels as equally spaced numerical values without justification.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/README.md

KNN depends on meaningful distances

K-Nearest Neighbors stores the training data and predicts from the majority class among the k nearest observations. The distance metric, feature scaling, dimensionality, and choice of k all change which observations count as neighbors.

How to interpret it: Scale numerical features before distance-based comparison when their units differ, and select k with validation. Small k can follow local noise, while large k creates smoother neighborhoods that may blur a real boundary.

Common mistakes
  • Letting a large-unit feature dominate distance solely because of its measurement scale.
  • Choosing k from training performance alone.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/lecture_examples/README.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Tree splits seek purer child nodes

A decision tree recursively applies feature-threshold rules. Gini impurity and entropy measure how mixed the classes are in a node, and a useful split reduces impurity or uncertainty in its children.

How to interpret it: Read a split as a local rule that partitions the current observations. Low impurity means one class dominates the node; it does not by itself prove that the rule will generalize to new data.

Common mistakes
  • Assuming every impurity-reducing training split improves validation performance.
  • Reading Gini impurity as a feature importance score.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/lecture_examples/README.md

Control tree complexity before it memorizes noise

Deep trees can keep making greedy splits until small training patterns are memorized. Maximum depth, minimum samples per split or leaf, pruning, and cost-complexity control reduce effective tree complexity.

How to interpret it: Compare training and validation behavior while changing a complexity control. A shallow tree may underfit, while an unconstrained tree can be accurate on training data yet fragile on unseen observations.

Common mistakes
  • Choosing the deepest tree because it has the highest training accuracy.
  • Calling a very deep tree easy to interpret merely because every rule is technically visible.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Separate probability estimation from the decision threshold

Logistic regression applies the sigmoid function to a linear score, producing an estimated positive-class probability between zero and one. A threshold, often 0.5 by default, then converts that probability into a class decision.

How to interpret it: Choose the threshold according to the cost of false positives and false negatives. Raising it usually produces fewer positive predictions; lowering it usually catches more positives but can also create more false alarms.

Common mistakes
  • Treating 0.5 as the correct threshold for every application.
  • Interpreting a positive coefficient as a guaranteed causal effect.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/lecture_examples/README.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Name each kind of classification outcome

For a binary classifier, the confusion matrix counts true positives, false positives, true negatives, and false negatives. These four counts distinguish correct decisions from the two error types.

How to interpret it: Define the positive class first, then ask which error matters in the application. False-positive rate divides false positives by all actual negatives, while false-negative rate divides false negatives by all actual positives.

Common mistakes
  • Swapping false positives and false negatives by forgetting what the actual class was.
  • Comparing error counts without considering the number of actual positives or negatives.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Choose metrics around the error cost

Precision is TP divided by TP plus FP and asks how often positive predictions are correct. Recall is TP divided by TP plus FN and asks how many actual positives were found. F-beta combines precision and recall, with beta above one emphasizing recall and beta below one emphasizing precision.

How to interpret it: Accuracy can hide failure on a rare class. Prefer precision when false positives are especially costly, recall when missing positives is especially costly, and an F-score when a stated balance between them is useful.

Common mistakes
  • Reporting only accuracy for a strongly imbalanced target.
  • Assuming F1 reveals whether precision or recall is the weaker component.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Evaluate rankings and probabilities, not only hard labels

The ROC curve plots true-positive rate against false-positive rate across thresholds, while ROC-AUC summarizes ranking quality. Log loss evaluates predicted probabilities directly and heavily penalizes confident wrong predictions.

How to interpret it: Use ROC-AUC to examine threshold-spanning ranking behavior and log loss when probability quality matters. A score-distribution view can reveal class overlap that makes threshold selection difficult, even when one hard-label metric looks acceptable.

Common mistakes
  • Reading AUC as accuracy at the default threshold.
  • Ignoring overconfident probability errors because the final class label happened to be the main reported output.

Sources: lectures/lecture_05_classification_part_1/lecture_notes.md; lectures/lecture_05_classification_part_1/practical_session/README.md

Visualization reference

Decision threshold and confusion matrix

These fixed illustrative scores separate probability estimation from the threshold used to make a positive or negative decision. Move the threshold to see how true positives, false positives, true negatives, false negatives, precision, and recall change together.

Graph fallback: At the 0.50 decision threshold, the fixed illustrative cases give TP 4, FP 2, TN 4, and FN 2. Precision and recall are both about 0.67. Raising the threshold predicts fewer positives; lowering it predicts more positives.

Class-aware decision boundary explorer

The same illustrative Class A and Class B points stay visibly tied to their class labels while you compare candidate linear boundaries. A boundary changes the predicted side of a point; it does not change its true class.

Graph fallback: Class A occupies the lower-left portion of the illustrative feature space and Class B the upper-right. Compare the balanced, conservative-positive, and permissive-positive boundaries while keeping the true A/B class labels fixed.

Quiz banks and answer review

Foundations

  1. Which task allows several labels to be assigned to one observation?

    • Multilabel classification
    • Binary classification
    • Ordinary regression

    Answer: Multilabel classification

    Explanation: In multilabel classification, several labels can apply simultaneously to the same observation.

  2. Why is feature scaling important for KNN?

    • Large-unit features can dominate distance
    • It makes every class balanced
    • It removes the need to select k

    Answer: Large-unit features can dominate distance

    Explanation: KNN relies directly on distances, so a feature with a large numerical scale can overwhelm other features even when that dominance is not meaningful.

  3. What usually happens as k becomes very large in KNN?

    • The decision regions become smoother
    • The model uses only one neighbor
    • Distance stops mattering

    Answer: The decision regions become smoother

    Explanation: Larger neighborhoods average over more observations, increasing smoothing and potentially blurring local class boundaries.

  4. What does low impurity mean in a decision-tree node?

    • One class dominates the node
    • All features have equal importance
    • The tree cannot overfit

    Answer: One class dominates the node

    Explanation: Gini impurity and entropy are low when the class labels in the node are relatively homogeneous.

  5. Which control directly limits how many levels a decision tree can grow?

    • Maximum depth
    • Probability threshold
    • Number of KNN neighbors

    Answer: Maximum depth

    Explanation: Maximum depth restricts tree complexity and can reduce the tendency to memorize small training patterns.

  6. What does the sigmoid function do in binary logistic regression?

    • Maps a linear score into a value from 0 to 1
    • Chooses the nearest neighbors
    • Builds axis-aligned splits

    Answer: Maps a linear score into a value from 0 to 1

    Explanation: The sigmoid transforms the linear score into an estimated positive-class probability.

  7. What normally happens when the positive-class decision threshold is lowered?

    • More observations are predicted positive
    • No predictions change
    • Only true negatives increase

    Answer: More observations are predicted positive

    Explanation: A lower threshold makes it easier for an estimated probability to qualify as positive, which can increase both true and false positives.

  8. Which confusion-matrix outcome is an actual positive predicted as negative?

    • False negative
    • False positive
    • True negative

    Answer: False negative

    Explanation: The prediction missed an actual positive, so the outcome is a false negative.

  9. Which metric asks how often positive predictions are correct?

    • Precision
    • Recall
    • False-negative rate

    Answer: Precision

    Explanation: Precision is TP divided by TP plus FP, so its denominator is all predicted positives.

  10. Which metric directly penalizes confident wrong probability predictions?

    • Log loss
    • Accuracy only
    • Tree depth

    Answer: Log loss

    Explanation: Log loss evaluates probabilities and imposes a large penalty when a wrong prediction is made with high confidence.

Applied

  1. A photo can be tagged both indoor and nature. Which target structure fits?

    • Multilabel
    • Multiclass with exactly one class
    • Continuous regression

    Answer: Multilabel

    Explanation: The labels are not mutually exclusive, so more than one can be correct for the same photo.

  2. A target has levels low, medium, and high. What must the analysis preserve?

    • Their natural order
    • Equal numeric gaps between levels
    • No relationship among levels

    Answer: Their natural order

    Explanation: Ordinal classes have meaningful order, but the spacing between adjacent levels is not automatically equal.

  3. A KNN model uses age in years and income in euros without scaling. What is the main risk?

    • Income may dominate the distance calculation
    • The tree becomes too deep
    • The sigmoid stops returning probabilities

    Answer: Income may dominate the distance calculation

    Explanation: The larger numerical scale can drive nearest-neighbor distances even if that influence is not substantively justified.

  4. How should k usually be selected for KNN?

    • With validation or cross-validation
    • From training accuracy alone
    • Always set to 1

    Answer: With validation or cross-validation

    Explanation: Validation checks the bias-variance tradeoff on held-out data rather than rewarding a neighborhood that merely fits training noise.

  5. A tree has tiny leaves that memorize rare training combinations. Which change directly addresses this?

    • Increase minimum samples per leaf
    • Lower the logistic threshold
    • Use more histogram bins

    Answer: Increase minimum samples per leaf

    Explanation: Requiring more observations in each leaf prevents the tree from creating rules for extremely small training groups.

  6. Missing a disease case is especially costly. Which threshold change commonly supports higher recall?

    • Lower the positive threshold
    • Raise the positive threshold
    • Remove probability estimates

    Answer: Lower the positive threshold

    Explanation: Lowering the threshold usually predicts more observations as positive and can catch more actual positives, though false positives may also rise.

  7. A classifier has 30 true positives and 10 false positives. What is its precision?

    • 0.75
    • 0.60
    • 0.30

    Answer: 0.75

    Explanation: Precision is 30 divided by 30 plus 10, which equals 0.75.

  8. A classifier has 30 true positives and 20 false negatives. What is its recall?

    • 0.60
    • 0.75
    • 0.40

    Answer: 0.60

    Explanation: Recall is 30 divided by 30 plus 20, which equals 0.60.

  9. Only 1 percent of cases are positive, and a model always predicts negative. Why is accuracy misleading?

    • It hides complete failure on the positive class
    • It directly measures probability calibration
    • It gives equal detail about both error types

    Answer: It hides complete failure on the positive class

    Explanation: The model can be 99 percent accurate while its recall for the rare positive class is zero.

  10. Which evaluation is most directly concerned with the quality of estimated probabilities?

    • Log loss
    • Maximum tree depth
    • KNN fit time

    Answer: Log loss

    Explanation: Log loss uses the predicted probabilities themselves rather than only the final hard labels.

Challenge

  1. Why can KNN degrade in a very high-dimensional feature space?

    • Near and far distances can become less distinguishable
    • Trees become probabilistic
    • All classes become ordinal

    Answer: Near and far distances can become less distinguishable

    Explanation: Distance concentration makes local neighborhoods less informative as dimensionality grows, especially with irrelevant features.

  2. What distinguishes weighted KNN from ordinary majority voting?

    • Closer neighbors receive more influence
    • Every feature receives the same scale
    • The model grows a deeper tree

    Answer: Closer neighbors receive more influence

    Explanation: Weighted KNN gives nearby observations larger votes because they may be more informative than distant neighbors.

  3. Why might a shallow decision tree struggle with a diagonal class boundary?

    • Its individual splits are axis-aligned
    • It cannot use numerical features
    • Gini impurity requires probabilities from logistic regression

    Answer: Its individual splits are axis-aligned

    Explanation: A tree partitions one feature at a time, so representing a diagonal boundary may require several rectangular regions.

  4. Which node has the lower Gini impurity?

    • A node containing only one class
    • A node split evenly between two classes
    • They always have equal impurity

    Answer: A node containing only one class

    Explanation: A pure node has Gini impurity zero, while an evenly mixed binary node has higher impurity.

  5. A deep tree has perfect training accuracy but much worse validation accuracy. What is the strongest diagnosis?

    • The tree is overfitting
    • The validation data proves the tree is pure
    • The model needs a lower logistic threshold

    Answer: The tree is overfitting

    Explanation: A large training-validation gap is consistent with memorizing training-specific patterns that do not generalize.

  6. What does choosing beta greater than 1 do in an F-beta score?

    • Gives recall more weight
    • Gives precision more weight
    • Turns the score into accuracy

    Answer: Gives recall more weight

    Explanation: The lecture defines beta above one as emphasizing recall and beta below one as emphasizing precision.

  7. What does ROC-AUC summarize?

    • Ranking behavior across thresholds
    • Accuracy at exactly 0.5
    • Only the false-negative count

    Answer: Ranking behavior across thresholds

    Explanation: The ROC curve varies the threshold, and its area summarizes how well scores rank positives relative to negatives.

  8. Two models make the same number of wrong labels, but one is extremely confident when wrong. Which metric exposes that difference?

    • Log loss
    • Hard-label accuracy alone
    • Maximum depth

    Answer: Log loss

    Explanation: Log loss penalizes a confident wrong probability more heavily, while hard-label accuracy records only that both predictions were wrong.

  9. False positives are very expensive. Which threshold change commonly reduces positive predictions?

    • Raise the positive threshold
    • Lower the positive threshold
    • Set every score to 0.5

    Answer: Raise the positive threshold

    Explanation: A higher threshold demands stronger estimated evidence before predicting positive, often reducing both true and false positive predictions.

  10. A regulated decision needs a compact, readable model and usable probabilities. Which lecture model is a strong baseline to assess?

    • Logistic regression
    • Unconstrained deep decision tree
    • KNN with unscaled features

    Answer: Logistic regression

    Explanation: Logistic regression offers smooth probability estimates and interpretable signed coefficients when a linear boundary is suitable, though validation and application-specific checks remain necessary.

Sources

  • lectures/lecture_05_classification_part_1/README.md
  • lectures/lecture_05_classification_part_1/lecture_notes.md