A comprehensive machine learning evaluation metrics library that provides a simple interface to calculate multiple evaluation metrics at once.
pip install mlscorefrom mlscore import score, score_c, score_r
import numpy as np
# Example 1: Classification
y_true = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
y_pred = np.array([0, 1, 0, 0, 0, 1, 0, 1, 0, 1])
# Using score_c for classification (automatically prints results)
score_c(y_true, y_pred)
# Example 2: Regression
y_true_reg = np.array([1.2, 2.3, 3.4, 4.5])
y_pred_reg = np.array([1.1, 2.4, 3.3, 4.6])
# Using score_r for regression (automatically prints results)
score_r(y_true_reg, y_pred_reg)
# Example 3: Automatic detection
score(y_true, y_pred) # Will automatically detect and print results# Get metrics dictionary without printing
metrics = score_c(y_true, y_pred, print_results=False)
# Access specific metrics
print(metrics['Accuracy'])
print(metrics['Precision'])
print(metrics['F1 Score'])-
score(y_true, y_pred, print_results=True)- Automatically detects if the problem is classification or regression
- Prints results by default
- Returns a dictionary of metrics
-
score_c(y_true, y_pred, print_results=True)- Specifically for classification problems
- Prints results by default
- Returns a dictionary of classification metrics
-
score_r(y_true, y_pred, print_results=True)- Specifically for regression problems
- Prints results by default
- Returns a dictionary of regression metrics
- Accuracy
- Precision
- Recall
- F1 Score
- ROC-AUC Score (for binary classification)
- Confusion Matrix
- Mean Squared Error (MSE)
- Root Mean Squared Error (RMSE)
- Mean Absolute Error (MAE)
- R² Score
- Adjusted R² Score
The library provides two ways to access the metrics:
- Printed Output (default):
==================================================
Problem Type: Classification
==================================================
Accuracy: 0.9000
Precision: 0.9167
Recall: 0.9000
F1 Score: 0.8990
ROC-AUC: 0.9000
Confusion Matrix:
[5, 0]
[1, 4]
- Dictionary Output:
{
'Accuracy': 0.9,
'Precision': 0.9167,
'Recall': 0.9,
'F1 Score': 0.8990,
'ROC-AUC': 0.9,
'Confusion Matrix': [[5, 0], [1, 4]],
'Problem Type': 'Classification'
}- Python >= 3.6
- NumPy >= 1.19.0
- scikit-learn >= 0.24.0
MIT License