ML Metrics¶
These functions compute standard machine learning evaluation metrics.
accuracy¶
Computes classification accuracy: the proportion of correct predictions.
Parameters:
y_true- Array of true labelsy_pred- Array of predicted labels
Returns: A number between 0.0 and 1.0.
Note
accuracy_score is an alias for accuracy.
f1_score¶
Computes the F1 score, the harmonic mean of precision and recall.
Parameters:
y_true- Array of true labelsy_pred- Array of predicted labels
Returns: A number between 0.0 and 1.0.
precision¶
Computes precision: the proportion of positive predictions that are correct.
Parameters:
y_true- Array of true labelsy_pred- Array of predicted labels
Returns: A number between 0.0 and 1.0.
Note
precision_score is an alias for precision.
recall¶
Computes recall: the proportion of actual positives that were correctly predicted.
Parameters:
y_true- Array of true labelsy_pred- Array of predicted labels
Returns: A number between 0.0 and 1.0.
Note
recall_score is an alias for recall.
confusion_matrix¶
Computes a multi-class confusion matrix.
Parameters:
y_true- Array of true labelsy_pred- Array of predicted labels
Returns: A 2D array where element [i][j] is the number of samples with true
label i predicted as label j.
roc_curve¶
Computes the Receiver Operating Characteristic (ROC) curve.
Parameters:
y_true- Array of true binary labelsy_pred- Array of predicted probabilities
Returns: A record with three fields:
"fpr"- Array of false positive rates"tpr"- Array of true positive rates"thresholds"- Array of thresholds
brier_score_model¶
Computes the Brier score (mean squared error) for probability predictions over the entire dataset.
Parameters:
y_true- Array of true binary labels (0 or 1)y_pred- Array of predicted probabilities
Returns: A single number. Lower is better; 0.0 is a perfect score.
brier_score_element¶
Computes per-element Brier scores, returning a score for each prediction.
Parameters:
y_true- Array of true binary labels (0 or 1)y_pred- Array of predicted probabilities
Returns: An array of per-element squared errors.