@@ -77,6 +77,7 @@ Scoring Function
77
77
'roc_auc_ovo' :func: `metrics.roc_auc_score `
78
78
'roc_auc_ovr_weighted' :func: `metrics.roc_auc_score `
79
79
'roc_auc_ovo_weighted' :func: `metrics.roc_auc_score `
80
+ 'd2_log_loss_score' :func: `metrics.d2_log_loss_score `
80
81
81
82
**Clustering**
82
83
'adjusted_mutual_info_score' :func: `metrics.adjusted_mutual_info_score `
@@ -377,6 +378,7 @@ Some also work in the multilabel case:
377
378
recall_score
378
379
roc_auc_score
379
380
zero_one_loss
381
+ d2_log_loss_score
380
382
381
383
And some work with binary and multilabel (but not multiclass) problems:
382
384
@@ -1986,6 +1988,71 @@ see the example below.
1986
1988
1987
1989
|details-end |
1988
1990
1991
+ .. _d2_score_classification :
1992
+
1993
+ D² score for classification
1994
+ ---------------------------
1995
+
1996
+ The D² score computes the fraction of deviance explained.
1997
+ It is a generalization of R², where the squared error is generalized and replaced
1998
+ by a classification deviance of choice :math: `\text {dev}(y, \hat {y})`
1999
+ (e.g., Log loss). D² is a form of a *skill score *.
2000
+ It is calculated as
2001
+
2002
+ .. math ::
2003
+
2004
+ D^2 (y, \hat {y}) = 1 - \frac {\text {dev}(y, \hat {y})}{\text {dev}(y, y_{\text {null}})} \,.
2005
+
2006
+ Where :math: `y_{\text {null}}` is the optimal prediction of an intercept-only model
2007
+ (e.g., the per-class proportion of `y_true ` in the case of the Log loss).
2008
+
2009
+ Like R², the best possible score is 1.0 and it can be negative (because the
2010
+ model can be arbitrarily worse). A constant model that always predicts
2011
+ :math: `y_{\text {null}}`, disregarding the input features, would get a D² score
2012
+ of 0.0.
2013
+
2014
+ |details-start |
2015
+ **D2 log loss score **
2016
+ |details-split |
2017
+
2018
+ The :func: `d2_log_loss_score ` function implements the special case
2019
+ of D² with the log loss, see :ref: `log_loss `, i.e.:
2020
+
2021
+ .. math ::
2022
+
2023
+ \text {dev}(y, \hat {y}) = \text {log_loss}(y, \hat {y}).
2024
+
2025
+ Here are some usage examples of the :func: `d2_log_loss_score ` function::
2026
+
2027
+ >>> from sklearn.metrics import d2_log_loss_score
2028
+ >>> y_true = [1, 1, 2, 3]
2029
+ >>> y_pred = [
2030
+ ... [0.5, 0.25, 0.25],
2031
+ ... [0.5, 0.25, 0.25],
2032
+ ... [0.5, 0.25, 0.25],
2033
+ ... [0.5, 0.25, 0.25],
2034
+ ... ]
2035
+ >>> d2_log_loss_score(y_true, y_pred)
2036
+ 0.0
2037
+ >>> y_true = [1, 2, 3]
2038
+ >>> y_pred = [
2039
+ ... [0.98, 0.01, 0.01],
2040
+ ... [0.01, 0.98, 0.01],
2041
+ ... [0.01, 0.01, 0.98],
2042
+ ... ]
2043
+ >>> d2_log_loss_score(y_true, y_pred)
2044
+ 0.981...
2045
+ >>> y_true = [1, 2, 3]
2046
+ >>> y_pred = [
2047
+ ... [0.1, 0.6, 0.3],
2048
+ ... [0.1, 0.6, 0.3],
2049
+ ... [0.4, 0.5, 0.1],
2050
+ ... ]
2051
+ >>> d2_log_loss_score(y_true, y_pred)
2052
+ -0.552...
2053
+
2054
+ |details-end |
2055
+
1989
2056
.. _multilabel_ranking_metrics :
1990
2057
1991
2058
Multilabel ranking metrics
@@ -2826,51 +2893,6 @@ Here are some usage examples of the :func:`d2_absolute_error_score` function::
2826
2893
2827
2894
|details-end |
2828
2895
2829
- |details-start |
2830
- **D² log loss score **
2831
- |details-split |
2832
-
2833
- The :func: `d2_log_loss_score ` function implements the special case
2834
- of D² with the log loss, see :ref: `log_loss `, i.e.:
2835
-
2836
- .. math ::
2837
-
2838
- \text {dev}(y, \hat {y}) = \text {log_loss}(y, \hat {y}).
2839
-
2840
- The :math: `y_{\text {null}}` for the :func: `log_loss ` is the per-class
2841
- proportion.
2842
-
2843
- Here are some usage examples of the :func: `d2_log_loss_score ` function::
2844
-
2845
- >>> from sklearn.metrics import d2_log_loss_score
2846
- >>> y_true = [1, 1, 2, 3]
2847
- >>> y_pred = [
2848
- ... [0.5, 0.25, 0.25],
2849
- ... [0.5, 0.25, 0.25],
2850
- ... [0.5, 0.25, 0.25],
2851
- ... [0.5, 0.25, 0.25],
2852
- ... ]
2853
- >>> d2_log_loss_score(y_true, y_pred)
2854
- 0.0
2855
- >>> y_true = [1, 2, 3]
2856
- >>> y_pred = [
2857
- ... [0.98, 0.01, 0.01],
2858
- ... [0.01, 0.98, 0.01],
2859
- ... [0.01, 0.01, 0.98],
2860
- ... ]
2861
- >>> d2_log_loss_score(y_true, y_pred)
2862
- 0.981...
2863
- >>> y_true = [1, 2, 3]
2864
- >>> y_pred = [
2865
- ... [0.1, 0.6, 0.3],
2866
- ... [0.1, 0.6, 0.3],
2867
- ... [0.4, 0.5, 0.1],
2868
- ... ]
2869
- >>> d2_log_loss_score(y_true, y_pred)
2870
- -0.552...
2871
-
2872
- |details-end |
2873
-
2874
2896
.. _visualization_regression_evaluation :
2875
2897
2876
2898
Visual evaluation of regression models
0 commit comments