Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Module

score

accuracy_score evaluates classification predictions by comparing true and predicted labels. It returns either the fraction of correct samples or their count, with optional sample weighting.

How it works

accuracy_score compares true and predicted class labels. It returns either the fraction of correct predictions or, when normalize is false, their count; sample_weight can weight individual samples.

Syntax

sklearn.metrics.accuracy_score(y_true, y_pred, *, normalize=True, sample_weight=None)

Parameters

NameTypeDescription
y_truearray-likeTrue class labels or multilabel targets.
y_predarray-likePredicted class labels or multilabel targets.
normalizeboolWhether to return the fraction of correct predictions (True) or their count (False). Default: True.
sample_weightarray-like of shape (n_samples,)Weights assigned to individual samples. Default: None.

Returns

score: float. The fraction of correctly classified samples when normalize=True, otherwise the number of correctly classified samples.

Key points

  • Use accuracy_score to evaluate how often predicted class labels match the true labels.
  • The normalize option defaults to True and selects a fraction rather than a raw correct-prediction count.
  • Setting normalize=False changes the output to the number of correct classifications.

Common mistakes

  • For multilabel targets, a prediction is correct only when the complete predicted label set exactly matches the true set.
  • Multilabel accuracy is strict subset accuracy rather than an average of independently correct labels.

Example: Fraction or count of correct predictions

from sklearn.metrics import accuracy_score

y_true = [0, 1, 1, 0]
y_pred = [0, 1, 0, 0]
print(accuracy_score(y_true, y_pred))
print(accuracy_score(y_true, y_pred, normalize=False))

Compute the fraction and then the count of correct classification predictions.

When to use it

Evaluate classification correctness

You need a single proportion summarizing ordinary single-label classification results.

Count correct predictions

You need an integer total for reporting how many predictions succeeded.

Apply sample weights

Observations have unequal importance or represent different amounts of data.

Assess multilabel exact matches

Each example has a set of labels and all labels must be right together.

Interview questions

QWhat does accuracy_score return by default?

accuracy_score measures classification accuracy by comparing y_true with y_pred. With normalize=True, it returns the fraction of correctly classified samples; with normalize=False, it returns the number of correct samples.

Follow-up: How can individual observations contribute unequally? Pass sample_weight, an array-like weight for each sample, so the score is weighted.

QHow do you get the number of correct predictions?

Set normalize=False to obtain the count of correctly classified samples instead of the fraction. The default, normalize=True, returns the fraction.

Follow-up: What happens when normalize is omitted? It remains True, so the result is the fraction rather than the count.

QHow is multilabel accuracy computed?

In multilabel classification, accuracy_score uses subset accuracy. Every label in a sample's predicted set must exactly match the corresponding true label set for that sample to count as correct.

Follow-up: Why can this be stricter than label-wise accuracy? A single incorrect or missing label makes the whole sample incorrect under subset accuracy.

  • balanced_accuracy_score
  • f1_score
  • precision_score
  • recall_score
  • zero_one_loss

Source: accuracy_score — scikit-learn 1.9.1 documentation. Checked 2026-10-15.