Artificial Intelligence Fundamentals / Learn From Labelled Data

Start with a baseline

Lesson 9 of 26. Open to read. No account needed.

Is 95% Good?

A model that detects faulty parts on a production line is right 95% of the time. That sounds impressive until you learn that 95% of the parts are fine. A "model" that declares every part fine, without looking at anything, is also right 95% of the time, and it never finds a single faulty part.

A score means nothing on its own. It needs a comparison: what would a trivial approach achieve on the same data? That comparison is a baseline. Measuring it first, before any real model, tells you what "better" has to mean.

What a Baseline Is

A baseline ignores the features entirely and makes the same simple guess for every sample:

  • For classification, guess the most common class from the training data.
  • For regression, predicting a number, guess the average of the training labels.

scikit-learn provides both as dummy models, which follow the usual fit and predict pattern:

  • DummyClassifier() uses the strategy "prior" by default. It learns how often each class appears in the training data and always predicts the most frequent one.
  • DummyRegressor() uses the strategy "mean" by default and always predicts the average training label.

These are not models anyone would use. They are the floor a real model must clear: if a model cannot beat its baseline, it has not learned anything useful from the features.

Accuracy and Imbalanced Classes

Accuracy is the share of predictions that are correct: correct predictions divided by all predictions, often written as a decimal, so 0.95 means 95%. It is the default score of every scikit-learn classifier's score method.

Accuracy becomes misleading when one class is much rarer than the other, a situation called imbalanced classes. Fraud, faulty parts, rare diseases and late deliveries are all usually rare. On such data the majority-class baseline reaches high accuracy while finding none of the rare cases, which are usually the ones you care about. The metrics lesson introduces measures, including recall, the share of real positive cases a model finds, that expose this.

Exercise: Measure Baselines First

You will measure a classification baseline on imbalanced generated data and a regression baseline on generated numbers.

Starting state: the course environment, active in your terminal. The script generates its own data.

  1. Create the exercise folder. macOS and Linux:

    mkdir -p ~/ai-practice/baseline-first
    cd ~/ai-practice/baseline-first
    

    Windows PowerShell:

    mkdir $HOME\ai-practice\baseline-first
    cd $HOME\ai-practice\baseline-first
    

    Save this as baseline_first.py in that folder:

    """Measure baselines for a classification task and a regression task."""
    from sklearn.datasets import make_classification, make_regression
    from sklearn.dummy import DummyClassifier, DummyRegressor
    from sklearn.model_selection import train_test_split
    
    # Classification: about 95% of cases are negative (0), 5% positive (1).
    X, y = make_classification(n_samples=1000, weights=[0.95], random_state=2)
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=2, stratify=y)
    baseline = DummyClassifier().fit(X_train, y_train)
    predictions = baseline.predict(X_test)
    print("Test cases:", len(y_test), "| positive:", y_test.sum())
    print("Baseline accuracy:", round(baseline.score(X_test, y_test), 3))
    print("Positive cases found:", ((predictions == 1) & (y_test == 1)).sum())
    
    # Regression: predict a number.
    X, y = make_regression(n_samples=300, n_features=3, noise=15, random_state=3)
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=3)
    mean_baseline = DummyRegressor().fit(X_train, y_train)
    print("Training mean:", round(y_train.mean(), 1))
    print("Baseline predictions:", mean_baseline.predict(X_test[:3]).round(1))
    
  2. Predict the baseline's accuracy, then run it:

    python baseline_first.py
    

    Output, which should match exactly:

    Test cases: 250 | positive: 13
    Baseline accuracy: 0.948
    Positive cases found: 0
    Training mean: 1.7
    Baseline predictions: [1.7 1.7 1.7]
    

How the Script Works

Imbalanced data. make_classification(n_samples=1000, weights=[0.95]) generates 1,000 samples in two classes, with about 95% in class 0. Class 1 is the rare "positive" class, such as a faulty part. The stratified split keeps that balance in the 250 test samples, of which 13 are positive.

The classification baseline. DummyClassifier() is fitted on the training labels only; it learns that class 0 is the most frequent. Its predictions are therefore 0 for all 250 test samples. baseline.score returns accuracy: 237 of 250 correct, 0.948. The last classification line counts the samples that are both predicted positive and really positive. (predictions == 1) and (y_test == 1) each give True or False per sample, & keeps the samples where both are True, and .sum() counts them: none.

The regression baseline. make_regression generates 300 samples whose label is a number, with noise=15 adding random variation. DummyRegressor() learns the training labels' average, 1.7, and predict returns 1.7 for every sample, as the first three predictions show. The regression lesson measures how far such predictions are from the truth.

If you changed weights=[0.95] to weights=[0.99], the baseline's accuracy would rise towards 0.99, while it still found no positive case: a better score for an equally useless model.

Success: you can state the classification baseline's accuracy, explain why it finds no positive cases, and say what the regression baseline predicts.

If something differs:

What you seeLikely causeNext step
Different counts or accuracyA random_state or weights value was changedRestore the values shown
Positive cases found: followed by a number above 0The DummyClassifier was given a strategy other than the defaultUse DummyClassifier() with no arguments
NameError: name 'X_train' is not definedThe split line was not pastedPaste the whole script again
ModuleNotFoundErrorThe course environment is not activeActivate it and rerun
  1. Clean up. macOS and Linux:

    cd ~/ai-practice
    ls
    rm -rf baseline-first
    ls
    

    Windows PowerShell:

    cd $HOME\ai-practice
    ls
    Remove-Item -Recurse baseline-first
    ls
    

    Check that the first ls shows baseline-first before removing it. Do the independent task first.

Independent task: change weights=[0.95] to weights=[0.5], which generates two equally common classes. Predict the baseline's accuracy before running the script, then check.

Check Your Understanding

  1. A model detecting a rare disease reports 95% accuracy. Why is that not enough to judge it, and what should be reported beside it?
  2. A new model scores 0.946 accuracy on the faulty-parts test data from the exercise. Is it better than the baseline?

Answer and Reasoning

Independent task

The baseline's accuracy falls to 0.5, and the test set holds 125 positive cases out of 250. With two equally common classes, always guessing one class is right half the time. The same baseline method gives 0.948 or 0.5 depending only on the class balance, which is why a model's score must always be compared with its own baseline on the same data.

Understanding check

  1. If 95% of patients do not have the disease, a model that never predicts it also scores 95%. Report the baseline's score on the same data beside it, and a measure of how many real cases the model finds, as the metrics lesson shows.
  2. No. It is slightly below the baseline's 0.948, so on accuracy it has not beaten the trivial guess. It might still find some faulty parts, which accuracy alone does not show.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy