Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MetricScore

Utility sklearn-compatible 📏 Metrics

Compute a named metric score (accuracy, r2, f1, etc.) from predictions. / Calcule un score de métrique nommée (accuracy, r2, f1, etc.) à partir des prédictions.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, json
payload = {"y_true": [0,1,1,0,1], "y_pred": [0,1,0,0,1], "metric": "accuracy"}
res = json.loads(sp.ml_metric_score(json.dumps(payload)))
print(res["score"])
💡
EN — Drop-in replacement: sp.MetricScore has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_metric_score — aliases: metric_score

Python class
sp.MetricScore(metric=accuracy)
Constructor Parameters
ParameterTypeDefaultDescription
metricstraccuracyMetric name: `accuracy`, `r2`, `f1`, `precision`, `recall`, `mse`, `mae`.
Returns

JSON with score.

Example
import seraplot as sp, json
payload = {"y_true": [0,1,1,0,1], "y_pred": [0,1,0,0,1], "metric": "accuracy"}
res = json.loads(sp.ml_metric_score(json.dumps(payload)))
print(res["score"])

Référence API

Nom de fonction JSON

ml_metric_score — alias : metric_score

Classe Python
sp.MetricScore(metric=accuracy)
Paramètres du constructeur
ParamètreTypeDéfautDescription
metricstraccuracyNom de la métrique : `accuracy`, `r2`, `f1`, `precision`, `recall`, `mse`, `mae`.
Retourne

JSON avec score.

Exemple
import seraplot as sp, json
payload = {"y_true": [0,1,1,0,1], "y_pred": [0,1,0,0,1], "metric": "accuracy"}
res = json.loads(sp.ml_metric_score(json.dumps(payload)))
print(res["score"])

MetricCurve

Utility sklearn-compatible 📏 Metrics

Compute a metric curve (ROC, PR, confusion matrix) from predictions. / Calcule une courbe de métrique (ROC, PR, matrice de confusion) à partir des prédictions.

⚡ Rust-native ✓ sklearn parity
Quick start — Python
import seraplot as sp, json
import numpy as np
y_true = (np.random.randn(100) > 0).astype(int).tolist()
y_score = np.random.rand(100).tolist()
res = json.loads(sp.ml_metric_curve(json.dumps({"y_true": y_true, "y_score": y_score, "curve": "roc"})))
💡
EN — Drop-in replacement: sp.MetricCurve has the same API as sklearn.
FR — Remplacement direct : même API que sklearn, changez l'import.

API Reference

JSON function name

ml_metric_curve — aliases: metric_curve

Python class
sp.MetricCurve(curve=roc)
Constructor Parameters
ParameterTypeDefaultDescription
curvestrrocCurve type: `roc`, `pr`, `confusion`.
Returns

JSON with curve data points.

Example
import seraplot as sp, json
import numpy as np
y_true = (np.random.randn(100) > 0).astype(int).tolist()
y_score = np.random.rand(100).tolist()
res = json.loads(sp.ml_metric_curve(json.dumps({"y_true": y_true, "y_score": y_score, "curve": "roc"})))

Référence API

Nom de fonction JSON

ml_metric_curve — alias : metric_curve

Classe Python
sp.MetricCurve(curve=roc)
Paramètres du constructeur
ParamètreTypeDéfautDescription
curvestrrocType de courbe : `roc`, `pr`, `confusion`.
Retourne

JSON avec les points de la courbe.

Exemple
import seraplot as sp, json
import numpy as np
y_true = (np.random.randn(100) > 0).astype(int).tolist()
y_score = np.random.rand(100).tolist()
res = json.loads(sp.ml_metric_curve(json.dumps({"y_true": y_true, "y_score": y_score, "curve": "roc"})))