Thursday, November 12, 2026

Dummy Classifier in scikit-learn: Why Every Model Needs a Baseline

Say a team trains a fraud model and reports 97% accuracy. It sounds strong until someone asks what share of transactions are fraud. The answer is about 3%, which means a model that says “not fraud” for every single transaction would score about 97% too, while catching nothing.

That is the job of a dummy classifier. A dummy classifier is a model that ignores the input features and predicts using a simple rule, such as “always predict the most common class”. It sets the score you get without learning anything, so you can tell whether a real model has learned something. In scikit-learn it is DummyClassifier, and it takes four lines to add to any project. This guide shows each strategy, runs a real comparison on imbalanced data, and explains which metrics make the baseline useful.

Key Takeaways

  • A dummy classifier predicts without looking at the features. Its score is the floor any useful model must clear.
  • On imbalanced data, accuracy is misleading: in our test, always predicting “not fraud” scored 96.6% accuracy and 0% fraud recall.
  • A logistic regression scored 97.0% accuracy, only 0.4 points above the dummy, which shows how little accuracy said about it.
  • Compare models on metrics that reward finding the minority class, such as balanced accuracy, recall or precision. The dummy scores 0.5 balanced accuracy by design.
  • Use strategy="most_frequent" or "prior" as the standard baseline, and "stratified" to see what random guessing in the right proportions gets.

What Is a Dummy Classifier?

A dummy classifier is a baseline model. It learns only the labels during fit, such as which class is most common, and then makes predictions that do not depend on the input at all. scikit-learn’s DummyClassifier supports five strategies:

Strategy What it predicts When to use it
"most_frequent" Always the most common training class The standard accuracy baseline
"prior" (default) Same predictions as most_frequent, and class shares from predict_proba Baseline for probability metrics like log loss
"stratified" Random classes, drawn in the training proportions What informed random guessing scores
"uniform" Random classes, each equally likely Pure chance with no knowledge of the data
"constant" A class you choose with constant= Baseline for a minority-class rule, such as “flag everything”

The random strategies give different results each run unless you set random_state. For regression, DummyRegressor does the same job, predicting the training mean, median, a quantile or a constant.

Why a Baseline Matters

A score only means something next to a reference point. “97% accuracy” could be excellent on a balanced problem and worthless on one where 97% of rows belong to one class. A baseline turns a number into a comparison: how much better is the model than doing nothing clever?

Baselines catch several common problems:

  • Class imbalance. The most common case, shown in the example below.
  • Features with no signal. If a model barely beats the dummy, the features may not carry the information you hoped.
  • Bugs in the pipeline. A model that scores below the dummy often points to shuffled labels, misaligned rows or leakage in the wrong direction.
  • Overstated results. Reporting the baseline next to the model keeps everyone honest about the actual gain.

A Runnable Example on Imbalanced Data

The script below generates 10,000 synthetic transactions with 20 features, of which about 3% are fraud. It compares two dummy strategies with a plain logistic regression and one that weights classes to compensate for the imbalance.

from sklearn.datasets import make_classification
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, balanced_accuracy_score, recall_score
from sklearn.model_selection import train_test_split

# 10,000 transactions, about 3% of them fraud (class 1).
X, y = make_classification(n_samples=10_000, n_features=20, n_informative=4,
                           weights=[0.97], flip_y=0.01, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=0)
print(f"Share of fraud in test set: {y_test.mean():.3f}")

models = {
    "Dummy (most_frequent)": DummyClassifier(strategy="most_frequent"),
    "Dummy (stratified)": DummyClassifier(strategy="stratified", random_state=0),
    "LogisticRegression": LogisticRegression(max_iter=1000),
    "LogReg (balanced)": LogisticRegression(max_iter=1000, class_weight="balanced"),
}

print(f"{'model':24}{'accuracy':>10}{'balanced acc':>14}{'fraud recall':>14}")
for name, model in models.items():
    pred = model.fit(X_train, y_train).predict(X_test)
    print(f"{name:24}{accuracy_score(y_test, pred):10.3f}"
          f"{balanced_accuracy_score(y_test, pred):14.3f}"
          f"{recall_score(y_test, pred):14.3f}")

Output (scikit-learn 1.9):

Share of fraud in test set: 0.034
model                     accuracy  balanced acc  fraud recall
Dummy (most_frequent)        0.966         0.500         0.000
Dummy (stratified)           0.929         0.498         0.035
LogisticRegression           0.970         0.559         0.118
LogReg (balanced)            0.710         0.680         0.647

Reading the Results

The most_frequent dummy scores 96.6% accuracy. It predicts “not fraud” for every row, so its accuracy equals the share of non-fraud transactions. It catches zero fraud. Its balanced accuracy, the average of the recall on each class, is exactly 0.5, the value for a model that has learned nothing.

The plain logistic regression looks strong on accuracy and weak on everything else. At 97.0% it beats the dummy by less than half a point, and it catches only 11.8% of fraud. Without the baseline, that 97.0% would sound like a finished model.

The class-weighted model is the useful one. Its accuracy drops to 71.0%, below the dummy, yet it finds 64.7% of fraud and its balanced accuracy rises to 0.680. It now flags many legitimate transactions too, so whether it is good enough depends on the cost of reviewing a false alarm. That is a business decision, but now it is an informed one.

The stratified dummy shows what random guessing gets. It flags rows at random in the training proportions, catches 3.5% of fraud, and scores about 0.5 balanced accuracy. Any model with real signal should beat it clearly.

How to Use a Dummy Classifier in Your Workflow

  1. Fit the baseline first. Before tuning any real model, fit DummyClassifier(strategy="most_frequent") on the same split or cross-validation folds.
  2. Choose metrics that fit the problem. For imbalanced classes, use balanced accuracy, recall, precision, F1 or average precision, not accuracy alone. Check that the dummy scores poorly on them, which shows the metric can tell models apart.
  3. Report the gap, not the score. “Recall 0.65 against 0.00 for the baseline” says more than “recall 0.65”.
  4. Re-run the baseline when the data changes. If the class balance shifts, the baseline shifts with it.

The same idea works for regression. A DummyRegressor that predicts the training mean gives an R-squared of about 0 on new data, so a regression model must beat that. For forecasts of a percentile rather than the mean, the training-set quantile is the natural baseline, scored with quantile (pinball) loss. And when a model’s gain comes from a preprocessing change, such as standardization or min-max scaling, the baseline tells you whether the gain is real progress or just catching up to chance.

Back to the Fraud Model

The team from the opening reported 97% accuracy. With a dummy classifier next to it, the story changes: the baseline scores 96.6% by catching nothing, and the model catches about 1 fraud case in 8. Switching to balanced accuracy and recall, and weighting the classes, gives a model that catches about 2 in 3, with a clear trade-off to discuss. Four lines of baseline code changed the decision.

Frequently Asked Questions

What Is the Default Strategy of DummyClassifier?

In current scikit-learn versions, the default is "prior". It predicts the most common class, like "most_frequent", and returns the training class shares from predict_proba. Older versions defaulted to "stratified", so set the strategy explicitly to keep results stable across versions.

Can a Real Model Score Worse Than a Dummy Classifier?

Yes, on accuracy, and sometimes for good reasons: our class-weighted model scored 71% accuracy against the dummy’s 96.6% while catching far more fraud. If a model scores worse on the metric you actually care about, check for bugs, leakage or features with no signal.

Should I Use DummyClassifier in Production?

No. It is a measuring stick for evaluation, not a model to deploy. Its only role is to show what score you would get without learning anything from the features.

Which Metric Should I Use With a Baseline?

Pick the metric that matches the cost of mistakes. For rare positive classes, recall, precision, F1, balanced accuracy and average precision all expose a do-nothing baseline. Accuracy is fine only when classes are roughly balanced and both kinds of error cost about the same.

Disclaimer: The content on this website reflects the views of contributing authors and not necessarily those of Generative AI Lab. This site may contain sponsored content, affiliate links, and material created with generative AI. Thank you for your support.

Generative AI Lab mascot
Generative AI Lab Editorial Team
Articles researched, written and edited by the Generative AI Lab team. About Generative AI Lab

Must read

- Advertisement -spot_img

More articles

- Advertisement -spot_img

Latest articles

Available for Amazon Prime