RuleTree.evaluation.evaluate_classification#
- evaluate_classification(y_true, y_pred, y_proba=None, labels=None) dict[source]#
Accuracy, F1, precision and recall of the predictions of a classifier and, with the class probabilities, ROC AUC and average precision.
F1, precision and recall are given with the micro, macro and weighted averages;
f1_score,precision_scoreandrecall_scoreare the ones of the positive class (the second one) for binary problems, and the micro averages otherwise.- Parameters:
y_true (array-like of shape (n_samples,)) – True classes.
y_pred (array-like of shape (n_samples,)) – Predicted classes.
y_proba (array-like of shape (n_samples, n_classes), default=None) – Predicted class probabilities (e.g.
predict_proba), in the order oflabels. If None, the metrics based on probabilities are not computed.labels (array-like of shape (n_classes,), default=None) – Classes, in the order of the columns of
y_proba(e.g.model.classes_). If None, the sorted classes ofy_true.
- Returns:
scores – Metric name -> value.
- Return type:
See also
sklearn.metricsthe definitions of the metrics.
Examples
>>> from sklearn.datasets import load_iris >>> from RuleTree import RuleTreeClassifier >>> from RuleTree.evaluation import evaluate_classification >>> X, y = load_iris(return_X_y=True) >>> model = RuleTreeClassifier(max_depth=2, random_state=0).fit(X, y) >>> scores = evaluate_classification(y, model.predict(X), model.predict_proba(X), labels=model.classes_) >>> round(scores["accuracy"], 3), round(scores["roc_macro"], 3) (0.96, 0.98)