SKLearner Home | About | Contact | Examples

Scikit-Learn brier_score_loss() Metric

The Brier score loss is a metric used to evaluate the accuracy of probabilistic predictions for classification problems. It measures the mean squared difference between the predicted probabilities and the actual binary outcomes. In other words, the Brier score loss quantifies how well a classifier’s predicted probabilities match the true labels.

The brier_score_loss() function in scikit-learn calculates the Brier score loss by taking the mean squared error between the predicted probabilities and the true labels. It returns a float value between 0 and 1, with 0 being perfect accuracy and 1 being the worst possible score.

The Brier score loss is commonly used for binary and multiclass classification problems where the classifier outputs probability estimates. However, it has some limitations. The Brier score loss is sensitive to class imbalance, meaning that it can be heavily influenced by the performance on the majority class in imbalanced datasets. Additionally, it treats all classes equally and does not take into account the relative costs of different types of misclassifications.

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import brier_score_loss

# Generate synthetic dataset
X, y = make_classification(n_samples=1000, n_classes=2, random_state=42)

# Split into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a logistic regression classifier
clf = LogisticRegression(random_state=42)
clf.fit(X_train, y_train)

# Predict probabilities on test set
y_prob = clf.predict_proba(X_test)

# Calculate Brier score loss
brier_loss = brier_score_loss(y_test, y_prob[:, 1])
print(f"Brier Score Loss: {brier_loss:.2f}")

Running the example gives an output like:

Brier Score Loss: 0.11
  1. Generate a synthetic binary classification dataset using make_classification().
  2. Split the dataset into training and test sets using train_test_split().
  3. Train a LogisticRegression classifier on the training set.
  4. Use the trained classifier to predict class probabilities on the test set with predict_proba().
  5. Calculate the Brier score loss using brier_score_loss() by comparing the predicted probabilities for the positive class to the true labels.

This example demonstrates how to use the brier_score_loss() function from scikit-learn to evaluate the performance of a binary classification model that outputs probability estimates.



See Also