26
26
from . import (r2_score , median_absolute_error , mean_absolute_error ,
27
27
mean_squared_error , mean_squared_log_error , accuracy_score ,
28
28
f1_score , roc_auc_score , average_precision_score ,
29
- precision_score , recall_score , log_loss , balanced_accuracy_score ,
30
- explained_variance_score , brier_score_loss )
29
+ precision_score , recall_score , log_loss ,
30
+ balanced_accuracy_score , explained_variance_score ,
31
+ brier_score_loss )
31
32
32
33
from .cluster import adjusted_rand_score
33
34
from .cluster import homogeneity_score
@@ -96,9 +97,32 @@ def __call__(self, estimator, X, y_true, sample_weight=None):
96
97
score : float
97
98
Score function applied to prediction of estimator on X.
98
99
"""
99
- super (_PredictScorer , self ).__call__ (estimator , X , y_true ,
100
- sample_weight = sample_weight )
101
100
y_pred = estimator .predict (X )
101
+ return self .score_predictions(y_true , y_pred , sample_weight )
102
+
103
+ def score_predictions (self , y_true , y_pred , sample_weight = None ):
104
+ """Evaluate predicted target values y_pred relative to y_true.
105
+
106
+ Parameters
107
+ ----------
108
+ y_pred : array-like
109
+ Prodicted values for y.
110
+
111
+ y_true : array-like
112
+ Gold standard target values for y.
113
+
114
+ sample_weight : array-like, optional (default=None)
115
+ Sample weights.
116
+
117
+ Returns
118
+ -------
119
+ score : float
120
+ Score function applied to prediction of estimator on X.
121
+ """
122
+ # We call __call__ with no arguments as it only serves to show
123
+ # deprecation warnings.
124
+ super (_PredictScorer , self ).__call__ (None , None , None ,
125
+ sample_weight = sample_weight )
102
126
if sample_weight is not None :
103
127
return self ._sign * self ._score_func (y_true , y_pred ,
104
128
sample_weight = sample_weight ,
@@ -109,7 +133,7 @@ def __call__(self, estimator, X, y_true, sample_weight=None):
109
133
110
134
111
135
class _ProbaScorer (_BaseScorer ):
112
- def __call__ (self , clf , X , y , sample_weight = None ):
136
+ def __call__ (self , clf , X , y_true , sample_weight = None ):
113
137
"""Evaluate predicted probabilities for X relative to y_true.
114
138
115
139
Parameters
@@ -121,7 +145,7 @@ def __call__(self, clf, X, y, sample_weight=None):
121
145
X : array-like or sparse matrix
122
146
Test data that will be fed to clf.predict_proba.
123
147
124
- y : array-like
148
+ y_true : array-like
125
149
Gold standard target values for X. These must be class labels,
126
150
not probabilities.
127
151
@@ -133,21 +157,49 @@ def __call__(self, clf, X, y, sample_weight=None):
133
157
score : float
134
158
Score function applied to prediction of estimator on X.
135
159
"""
136
- super (_ProbaScorer , self ).__call__ (clf , X , y ,
137
- sample_weight = sample_weight )
138
- y_type = type_of_target (y )
139
160
y_pred = clf .predict_proba (X )
161
+
162
+ return self .score_predictions (y_true , y_pred , sample_weight )
163
+
164
+ def _factory_args (self ):
165
+ return ", needs_proba=True"
166
+
167
+ def score_predictions (self , y_true , y_pred , sample_weight = None ):
168
+ """Evaluate predicted y_pred relative to y_true.
169
+
170
+ Parameters
171
+ ----------
172
+ y_pred : array-like
173
+ Predicted values for y by a classifier. These must be class labels,
174
+ not probabilities.
175
+
176
+ y_true : array-like
177
+ Gold standard target values for y. These must be class labels,
178
+ not probabilities.
179
+
180
+ sample_weight : array-like, optional (default=None)
181
+ Sample weights.
182
+
183
+ Returns
184
+ -------
185
+ score : float
186
+ Score function applied to prediction of estimator on X.
187
+ """
188
+ # We call __call__ with no arguments as it only serves to show
189
+ # deprecation warnings.
190
+ super (_ProbaScorer , self ).__call__ (None , None , None ,
191
+ sample_weight = sample_weight )
192
+ y_type = type_of_target (y_true )
140
193
if y_type == "binary" :
141
194
y_pred = y_pred [:, 1 ]
142
195
if sample_weight is not None :
143
- return self ._sign * self ._score_func (y , y_pred ,
196
+ return self ._sign * self ._score_func (y_true , y_pred ,
144
197
sample_weight = sample_weight ,
145
198
** self ._kwargs )
146
199
else :
147
- return self ._sign * self ._score_func (y , y_pred , ** self ._kwargs )
148
-
149
- def _factory_args (self ):
150
- return ", needs_proba=True"
200
+ return self ._sign * self ._score_func (y_true ,
201
+ y_pred ,
202
+ ** self ._kwargs )
151
203
152
204
153
205
class _ThresholdScorer (_BaseScorer ):
0 commit comments