sklearn.metrics#

Score functions, performance metrics, pairwise metrics and distance computations.

User guide. See the Metrics and scoring: quantifying the quality of predictions and Pairwise metrics, Affinities and Kernels sections for further details.

Model selection interface#

User guide. See the The scoring parameter: defining model evaluation rules section for further details.

check_scoring

Determine scorer from user options.

get_scorer

Get a scorer from string.

get_scorer_names

Get the names of all available scorers.

make_scorer

Make a scorer from a performance metric or loss function.

Classification metrics#

User guide. See the Classification metrics section for further details.

accuracy_score

Accuracy classification score.

auc

Compute Area Under the Curve (AUC) using the trapezoidal rule.

average_precision_score

Compute average precision (AP) from prediction scores.

balanced_accuracy_score

Compute the balanced accuracy.

brier_score_loss

Compute the Brier score loss.

class_likelihood_ratios

Compute binary classification positive and negative likelihood ratios.

classification_report

Build a text report showing the main classification metrics.

cohen_kappa_score

Compute Cohen's kappa: a statistic that measures inter-annotator agreement.

confusion_matrix

Compute confusion matrix to evaluate the accuracy of a classification.

d2_log_loss_score

\(D^2\) score function, fraction of log loss explained.

dcg_score

Compute Discounted Cumulative Gain.

det_curve

Compute error rates for different probability thresholds.

f1_score

Compute the F1 score, also known as balanced F-score or F-measure.

fbeta_score

Compute the F-beta score.

hamming_loss

Compute the average Hamming loss.

hinge_loss

Average hinge loss (non-regularized).

jaccard_score

Jaccard similarity coefficient score.

log_loss

Log loss, aka logistic loss or cross-entropy loss.

matthews_corrcoef

Compute the Matthews correlation coefficient (MCC).

multilabel_confusion_matrix

Compute a confusion matrix for each class or sample.

ndcg_score

Compute Normalized Discounted Cumulative Gain.

precision_recall_curve

Compute precision-recall pairs for different probability thresholds.

precision_recall_fscore_support

Compute precision, recall, F-measure and support for each class.

precision_score

Compute the precision.

recall_score

Compute the recall.

roc_auc_score

Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores.

roc_curve

Compute Receiver operating characteristic (ROC).

top_k_accuracy_score

Top-k Accuracy classification score.

zero_one_loss

Zero-one classification loss.

Regression metrics#

User guide. See the Regression metrics section for further details.

d2_absolute_error_score

\(D^2\) regression score function, fraction of absolute error explained.

d2_pinball_score

\(D^2\) regression score function, fraction of pinball loss explained.

d2_tweedie_score

\(D^2\) regression score function, fraction of Tweedie deviance explained.

explained_variance_score

Explained variance regression score function.

max_error

The max_error metric calculates the maximum residual error.

mean_absolute_error

Mean absolute error regression loss.

mean_absolute_percentage_error

Mean absolute percentage error (MAPE) regression loss.

mean_gamma_deviance

Mean Gamma deviance regression loss.

mean_pinball_loss

Pinball loss for quantile regression.

mean_poisson_deviance

Mean Poisson deviance regression loss.

mean_squared_error

Mean squared error regression loss.

mean_squared_log_error

Mean squared logarithmic error regression loss.

mean_tweedie_deviance

Mean Tweedie deviance regression loss.

median_absolute_error

Median absolute error regression loss.

r2_score

\(R^2\) (coefficient of determination) regression score function.

root_mean_squared_error

Root mean squared error regression loss.

root_mean_squared_log_error

Root mean squared logarithmic error regression loss.

Multilabel ranking metrics#

User guide. See the Multilabel ranking metrics section for further details.

coverage_error

Coverage error measure.

label_ranking_average_precision_score

Compute ranking-based average precision.

label_ranking_loss

Compute Ranking loss measure.

Clustering metrics#

Evaluation metrics for cluster analysis results.

  • Supervised evaluation uses a ground truth class values for each sample.

  • Unsupervised evaluation does use ground truths and measures the “quality” of the model itself.

User guide. See the Clustering performance evaluation section for further details.

adjusted_mutual_info_score

Adjusted Mutual Information between two clusterings.

adjusted_rand_score

Rand index adjusted for chance.

calinski_harabasz_score

Compute the Calinski and Harabasz score.

cluster.contingency_matrix

Build a contingency matrix describing the relationship between labels.

cluster.pair_confusion_matrix

Pair confusion matrix arising from two clusterings.

completeness_score

Compute completeness metric of a cluster labeling given a ground truth.

davies_bouldin_score

Compute the Davies-Bouldin score.

fowlkes_mallows_score

Measure the similarity of two clusterings of a set of points.

homogeneity_completeness_v_measure

Compute the homogeneity and completeness and V-Measure scores at once.

homogeneity_score

Homogeneity metric of a cluster labeling given a ground truth.

mutual_info_score

Mutual Information between two clusterings.

normalized_mutual_info_score

Normalized Mutual Information between two clusterings.

rand_score

Rand index.

silhouette_samples

Compute the Silhouette Coefficient for each sample.

silhouette_score

Compute the mean Silhouette Coefficient of all samples.

v_measure_score

V-measure cluster labeling given a ground truth.

Biclustering metrics#

User guide. See the Biclustering evaluation section for further details.

consensus_score

The similarity of two sets of biclusters.

Distance metrics#

DistanceMetric

Uniform interface for fast distance metric functions.

Pairwise metrics#

Metrics for pairwise distances and affinity of sets of samples.

User guide. See the Pairwise metrics, Affinities and Kernels section for further details.

pairwise.additive_chi2_kernel

Compute the additive chi-squared kernel between observations in X and Y.

pairwise.chi2_kernel

Compute the exponential chi-squared kernel between X and Y.

pairwise.cosine_distances

Compute cosine distance between samples in X and Y.

pairwise.cosine_similarity

Compute cosine similarity between samples in X and Y.

pairwise.distance_metrics

Valid metrics for pairwise_distances.

pairwise.euclidean_distances

Compute the distance matrix between each pair from a vector array X and Y.

pairwise.haversine_distances

Compute the Haversine distance between samples in X and Y.

pairwise.kernel_metrics

Valid metrics for pairwise_kernels.

pairwise.laplacian_kernel

Compute the laplacian kernel between X and Y.

pairwise.linear_kernel

Compute the linear kernel between X and Y.

pairwise.manhattan_distances

Compute the L1 distances between the vectors in X and Y.

pairwise.nan_euclidean_distances

Calculate the euclidean distances in the presence of missing values.

pairwise.paired_cosine_distances

Compute the paired cosine distances between X and Y.

pairwise.paired_distances

Compute the paired distances between X and Y.

pairwise.paired_euclidean_distances

Compute the paired euclidean distances between X and Y.

pairwise.paired_manhattan_distances

Compute the paired L1 distances between X and Y.

pairwise.pairwise_kernels

Compute the kernel between arrays X and optional array Y.

pairwise.polynomial_kernel

Compute the polynomial kernel between X and Y.

pairwise.rbf_kernel

Compute the rbf (gaussian) kernel between X and Y.

pairwise.sigmoid_kernel

Compute the sigmoid kernel between X and Y.

pairwise_distances

Compute the distance matrix from a vector array X and optional Y.

pairwise_distances_argmin

Compute minimum distances between one point and a set of points.

pairwise_distances_argmin_min

Compute minimum distances between one point and a set of points.

pairwise_distances_chunked

Generate a distance matrix chunk by chunk with optional reduction.

Plotting#

User guide. See the Visualizations section for further details.

ConfusionMatrixDisplay

Confusion Matrix visualization.

DetCurveDisplay

DET curve visualization.

PrecisionRecallDisplay

Precision Recall visualization.

PredictionErrorDisplay

Visualization of the prediction error of a regression model.

RocCurveDisplay

ROC Curve visualization.