Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 24

Understanding and Establishing Baseline Models

Recommended resources

Hello! Welcome to the final lesson in our module on the Fundamentals of Model Validation.

In our previous lessons, we've focused on diagnosing a model's performance. We've learned to split data, use cross-validation to get robust estimates, and interpret learning curves to identify underfitting (high bias) and overfitting (high variance). These are all crucial skills for understanding how a model is behaving.

However, this analysis is missing a key piece of context. If your classification model achieves 85% accuracy, is that good? If a regression model has an RMSE of $40,000, is that acceptable? The answer is: it depends. To make any meaningful judgment about a model's performance, we need a point of comparison.

That's the focus of today's lesson. Your learning outcome is to explain the purpose of a baseline model and establish one for a given problem. A baseline provides the "common sense" benchmark that any sophisticated model must outperform to be considered useful. It's the first and most important step in evaluating your work.

1. What is a Baseline Model and Why is it Essential?

Before we jump into the code, let's build a strong conceptual foundation. A baseline model isn't meant to be your final, production-ready solution. Instead, think of it as a "control group" in a scientific experiment. It's a simple, quick-to-build model that gives you a reference point to measure the performance of more complex models against.

To explore this idea further, let's look at a well-written article that demystifies the role of baselines.

Baseline models demystified: a practical guide

This blog post from OpenLayer clearly defines what a baseline is and why it's a non-negotiable step in any serious machine learning project.

Please read the sections 'What is a baseline model?' and 'Why are baseline models useful?'. As you read, think about the three key characteristics of a good baseline: simple, reasonable, and fast to build.

As the article highlights, establishing a baseline serves several critical purposes:

  • It provides a performance floor: Your advanced model must do better than the baseline. If it doesn't, it's not adding any value and may even be flawed.
  • It helps you understand your data: Building a simple baseline often reveals important characteristics of your dataset, like class imbalance or the predictive power of a key feature.
  • It accelerates your workflow: It gives you a working end-to-end pipeline quickly, which you can then iterate on. You can unblock other parts of a project by providing a "good enough for now" model.

The following flowchart provides a great visual summary of these benefits.

Reasons for Using a Baseline Model
This flowchart illustrates the core reasons for using a baseline model: to better understand your data (e.g., identify difficult classes), to iterate faster (e.g., unblock downstream processes), and to benchmark your metrics (e.g., provide a relative performance standard).

2. Establishing a "Dumb" Baseline

The simplest type of baseline is often called a "dumb" or "zero-rule" model. It uses no intelligence or feature information to make predictions. Its purpose is to answer the question: "What is the absolute minimum performance we should expect?"

There are two common strategies for this:

  1. Random Guessing: For a classification problem with 3 balanced classes, randomly guessing would yield an accuracy of about 33%.
  2. Predicting a Constant:
    • For classification, always predict the most frequent class from the training set.
    • For regression, always predict the mean (or median) value from the training set.

Let's see this in action. The following video explains the random guessing baseline and then transitions into a more practical rule-based approach, which we'll discuss next. For now, focus on the first part.

Intro to Machine Learning with Python 3: Train Test Split and Baseline Modeling

To make this concrete, let's see how to establish the most basic type of baseline: random guessing. This video explains the concept using the familiar Iris dataset.

Watch from 07:41 to 11:17. The key idea here is to calculate the performance you'd get with no intelligence at all. Notice how, for a balanced 3-class problem, the random-guess accuracy is simply 1/3.

While thinking about random guessing is useful, the "predicting a constant" strategy is more common in practice. Fortunately, scikit-learn provides convenient tools to implement this with just a few lines of code.

3. Baseline models & k-Nearest Neighbours

Scikit-learn provides DummyClassifier and DummyRegressor to create these simple baselines. Let's see how to use them.

Please read sections 3.3, 3.3.1, and 3.3.2 (you can find these under the heading 'Baseline Models'). Focus on: The concept of a baseline as a 'control group'. How DummyClassifier(strategy='most_frequent') works for classification. How DummyRegressor(strategy='mean') works for regression and why its R-squared score is 0.0 on the training data.

To summarize the practical implementation:

  • For classification: dummy_clf = DummyClassifier(strategy="most_frequent")
  • For regression: dummy_reg = DummyRegressor(strategy="mean")

The fact that the DummyRegressor scores an of 0 is a critical concept. By definition, an of 0 means your model is no better than one that simply predicts the mean of the target variable—which is exactly what the dummy regressor does! Any real regression model you build must achieve an to be considered useful.


3. Establishing a Simple, Rule-Based Baseline

A baseline doesn't have to be "dumb." You can use insights from your Exploratory Data Analysis (EDA) to create a simple but more intelligent baseline. This is a fantastic way to bridge the gap between data exploration and modeling. A simple if/else rule based on a single, powerful feature can often set a surprisingly strong performance benchmark.

The video from the previous section demonstrates this perfectly. It shows how to build a manual model for the Iris dataset based on a single feature, petal length, and then compares its performance to the "dumb" random-guessing baseline.

Intro to Machine Learning with Python 3: Train Test Split and Baseline Modeling

Now, let's see how we can create a more powerful baseline using simple, human-defined rules. This approach connects your EDA insights directly to a model.

Watch from 11:17 to 24:16. You don't need to code along, but pay close attention to the process: Looking at a plot (EDA) to find a simple rule (e.g., 'if petal length < 2.5'). Translating that rule into a simple Python function (if/elif/else). Applying that function to make predictions and calculating its accuracy. Comparing this new baseline's performance (95.5%) to the random-guess baseline (33%).

The result is striking: a simple, one-feature model achieves over 95% accuracy! This demonstrates two things:

  1. The Iris dataset is relatively easy.
  2. A simple, interpretable model can be incredibly effective and set a high bar for more complex models. If your fancy deep learning model can't beat this simple rule, you have a problem.

As the video notes, this if/else logic is conceptually what a Decision Tree does, just automated. This highlights how baselines can build your intuition for how more advanced algorithms work.


Conclusion

You've now reached the end of the "Fundamentals of Model Validation" module. You have a complete toolkit for assessing model performance: you know how to split data correctly, get robust performance estimates with cross-validation, diagnose bias and variance with learning curves, and now, how to set a meaningful benchmark with a baseline model. You're no longer just training models; you're evaluating them like a professional.

Key Takeaways:

  • Purpose: A baseline model is a simple, fast-to-build model that serves as a reference point or "performance floor" for evaluating more complex models.
  • "Dumb" Baselines: These are the simplest form, typically predicting the most frequent class (DummyClassifier) or the mean value (DummyRegressor). They establish the absolute minimum performance to beat.
  • Simple Rule-Based Baselines: You can create more intelligent baselines using simple rules (e.g., if/else statements) derived from EDA. These can be surprisingly effective.
  • The Workflow: Always start your modeling process by establishing a baseline. It provides essential context for every subsequent result and ensures you're creating real value.

Preview of the next lesson:

With this solid foundation in model validation, you are ready to start building and evaluating different types of models in depth. In the next module, "Supervised Learning: Regression," we will dive into our first major family of models. You'll begin by learning how to fit a simple linear regression model using scikit-learn and interpret its coefficients, using the evaluation techniques you've just mastered to judge its performance against a baseline.