Skip to main content

Welcome to a Grasp lesson

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

Lesson 7

Establishing a Baseline Model

Recommended resources

Welcome to your seventh lesson. In our last session, we constructed a robust and reproducible workflow using scikit-learn's Pipeline and ColumnTransformer. This was a crucial step from an architectural perspective, ensuring that our entire sequence of data processing and modeling is encapsulated into a single, deployable artifact.

Now that we have a reliable method for training and evaluating models, we must answer a fundamental question: how do we know if our model is any good? An accuracy of 90% or a root-mean-square error of 50 might sound impressive, but these numbers are meaningless without a reference point.

This lesson introduces the concept of a baseline model. We will explore why establishing a simple, common-sense performance benchmark is the non-negotiable first step in any serious modeling project. For you, as an architect, this isn't just a data science ritual; it's a core principle of project management, resource allocation, and risk mitigation.

The Strategic Importance of a Baseline

Before diving into complex algorithms, it's essential to establish a floor for performance. A baseline model provides this floor. It's typically simple, quick to implement, and serves as the yardstick against which all more sophisticated models must prove their worth.

The article "Why You Should Always Start With a Baseline Model" provides an excellent rationale for this practice.

Why You Should Always Start With a Baseline Model | Towards AI

This article from Towards AI clearly explains the strategic value of creating a baseline before attempting more complex modeling.

Please read the article from the beginning up to the section "But what is a good baseline model?". As you read, focus on the four key benefits it outlines: Context: How does a baseline help interpret performance metrics? Decision-Making: How does it inform whether a complex model's cost is justified? Faster Iteration: How does it provide early feedback on your data and problem? Production Exposure: How can a simple baseline de-risk your deployment pipeline?

The point about early production exposure is particularly relevant from an architectural standpoint. By building and deploying a simple baseline, you can validate your entire MLOps infrastructure—data ingestion, model serving, and monitoring—before investing heavily in complex model development. This is a powerful strategy for de-risking a project.

As the "Full Stack Deep Learning" course emphasizes, skipping a baseline, especially under a tight deadline, is a common but costly mistake. The debugging process for a complex model is far more efficient when you have a simple, working model to compare against.

6. Baselines - ML Projects - Full Stack Deep Learning

This video excerpt discusses a common pitfall in ML projects.

Watch the segment from this question, where the speaker explains why skipping the baseline is a mistake, even when time is limited.


What Constitutes a Good Baseline?

Now that we've established the "why," let's focus on the "what." A baseline doesn't need to be sophisticated. In fact, its strength lies in its simplicity. There are generally two categories of baselines.

1. Heuristic or "Dumb" Baselines

These models don't involve any real "learning." They rely on simple statistical properties of the data. They are the absolute minimum bar your model must clear.

  • For Regression: Predicting the mean or median of the target variable for every single data point.
  • For Classification: Always predicting the most frequent class (majority class). This is especially important for imbalanced datasets, where a model can achieve high accuracy simply by guessing the dominant class. Another option is predicting classes randomly, but respecting the training set's class distribution.
  • For Time Series: Predicting the last observed value (also known as a "persistence" or "naive" forecast).

2. Simple Machine Learning Baselines

This is a slightly more sophisticated baseline that involves training a simple, fast, and interpretable model. This helps you understand if there is any learnable signal in your features at all.

  • Good examples include:
    • Linear Regression / Logistic Regression
    • k-Nearest Neighbors (k-NN)
    • A simple Decision Tree with a limited depth

The following article provides a great overview of these common baseline types.

Baseline Machine Learning Models: Importance and Applications

This article catalogs common baseline strategies for different machine learning problems.

Please read the first three sections: "Why Establish a Baseline in Machine Learning?", "Common Types of Baseline Models", and "Baseline Model Examples for Specific Use Cases". Pay attention to the examples given for classification and regression tasks.


Implementing and Evaluating a Baseline

scikit-learn provides convenient tools for creating heuristic baselines through its "dummy" estimators.

  • DummyRegressor for regression tasks.
  • DummyClassifier for classification tasks.

These estimators can be configured with different "strategies." For example, DummyRegressor(strategy='mean') will always predict the mean of the training target values.

Let's see how this works in practice. Imagine we are building a regression model. Our first step is to establish a baseline by comparing a DummyRegressor to a simple LinearRegression model.

from sklearn.model_selection import cross_val_score
from sklearn.dummy import DummyRegressor
from sklearn.linear_model import LinearRegression
from sklearn.datasets import make_regression
import numpy as np




# Generate sample regression data
X, y = make_regression(n_samples=100, n_features=1, noise=20, random_state=42)




# 1. Heuristic Baseline (predicting the mean)
dummy_model = DummyRegressor(strategy="mean")
dummy_scores = cross_val_score(dummy_model, X, y, cv=5, scoring='r2')
print(f"Dummy Regressor R²: {np.mean(dummy_scores):.2f}")




# 2. Simple ML Baseline
linear_model = LinearRegression()
linear_scores = cross_val_score(linear_model, X, y, cv=5, scoring='r2')
print(f"Linear Regression R²: {np.mean(linear_scores):.2f}")




# Expected Output:
# Dummy Regressor R²: -0.06
# Linear Regression R²: 0.82

In this example, we use cross_val_score (which you'll recall from our lesson on validation) to get a robust estimate of the R-squared score for both models.

  • The DummyRegressor achieves an R² score of approximately -0.06. An R² of 0 means the model is no better than always predicting the mean. A negative R² indicates the model is performing even worse than that horizontal line benchmark on the test folds. This is our "dumb" baseline.
  • The LinearRegression model achieves an R² of about 0.82. This is a significant improvement over the baseline, justifying its use and telling us there is a clear linear signal in the data.

The following plot provides a powerful visual for this comparison.

This scatter plot shows the ground truth data (blue), predictions from a `DummyRegressor` that always outputs the mean (orange), and predictions from a `LinearRegressor` (green). The R² scores clearly show the `LinearRegressor` captures the trend, while the `DummyRegressor` provides a simple, horizontal-line benchmark.

The Baseline in the MLOps Lifecycle

From an architect's perspective, the baseline is the starting point for the entire MLOps workflow. It's the first model that should pass through your automated pipelines.

This diagram shows a complete MLOps pipeline on AWS. A baseline model is the perfect candidate for the first run through this entire system, from the "Model Build Pipeline" (CodeCommit, CodeBuild, SageMaker) to the "Model Deploy Pipeline" (CodeFormation, SageMaker Endpoint).

By using a DummyRegressor or a simple LinearRegression model as your first candidate, you can:

  1. Start Build (1): Trigger the pipeline.
  2. Start Pipeline (2): Run your scikit-learn Pipeline object, which now contains the baseline model.
  3. Register Model (3): Successfully register this simple model in the Amazon SageMaker Model Registry.
  4. Approve & Deploy (4, 5): Deploy this baseline to a staging endpoint.
  5. Monitor (6): Begin testing your model monitoring and feedback loop infrastructure.

This approach allows you to build and debug the full end-to-end infrastructure with a model that is guaranteed to run quickly and without complex dependencies. Once the pipes are proven to work, you can iterate by introducing more complex models into the same automated workflow.


Conclusion

In this lesson, we have established the critical role of baseline models in a machine learning project. They are not a mere academic exercise but a strategic tool for managing projects, making informed decisions, and de-risking the technical implementation.

Here are the key takeaways:

  • Baselines Provide Context: They turn abstract metrics like accuracy or R² into meaningful indicators of performance. A model is only "good" if it significantly outperforms a simple, common-sense baseline.
  • Justify Complexity: A baseline forces you to justify the cost (in time, money, and maintenance) of more complex models. If your advanced neural network only marginally beats a simple linear regression, is it worth it?
  • Two Levels of Baselines: You should establish at least two: a simple heuristic (e.g., predicting the mean) and a simple but true ML model (e.g., linear regression).
  • De-risk the MLOps Pipeline: Deploying a simple baseline first is an architectural best practice to validate your entire production infrastructure before tackling complex model development.

You now have a framework for starting any new modeling task: first, define your success metric; second, build a reproducible workflow; and third, establish a strong performance baseline.

In our next and final lesson of this module, we will build upon this foundation to design a model comparison experiment, allowing you to systematically evaluate multiple candidate models against your baseline and select the best one for the job.