@@ -39,7 +39,7 @@ def __init__(self, score_func, sign, kwargs):
3939 self ._sign = sign
4040
4141 @abstractmethod
42- def __call__ (self , estimator , X , y ):
42+ def __call__ (self , estimator , X , y , sample_weight = None ):
4343 pass
4444
4545 def __repr__ (self ):
@@ -56,7 +56,7 @@ def _factory_args(self):
5656
5757
5858class _PredictScorer (_BaseScorer ):
59- def __call__ (self , estimator , X , y_true ):
59+ def __call__ (self , estimator , X , y_true , sample_weight = None ):
6060 """Evaluate predicted target values for X relative to y_true.
6161
6262 Parameters
@@ -71,17 +71,26 @@ def __call__(self, estimator, X, y_true):
7171 y_true : array-like
7272 Gold standard target values for X.
7373
74+ sample_weight : array-like, optional (default=None)
75+ Sample weights.
76+
7477 Returns
7578 -------
7679 score : float
7780 Score function applied to prediction of estimator on X.
7881 """
7982 y_pred = estimator .predict (X )
80- return self ._sign * self ._score_func (y_true , y_pred , ** self ._kwargs )
81-
83+ if sample_weight is not None :
84+ return self ._sign * self ._score_func (y_true , y_pred ,
85+ sample_weight = sample_weight ,
86+ ** self ._kwargs )
87+ else :
88+ return self ._sign * self ._score_func (y_true , y_pred ,
89+ ** self ._kwargs )
90+
8291
8392class _ProbaScorer (_BaseScorer ):
84- def __call__ (self , clf , X , y ):
93+ def __call__ (self , clf , X , y , sample_weight = None ):
8594 """Evaluate predicted probabilities for X relative to y_true.
8695
8796 Parameters
@@ -97,20 +106,28 @@ def __call__(self, clf, X, y):
97106 Gold standard target values for X. These must be class labels,
98107 not probabilities.
99108
109+ sample_weight : array-like, optional (default=None)
110+ Sample weights.
111+
100112 Returns
101113 -------
102114 score : float
103115 Score function applied to prediction of estimator on X.
104116 """
105117 y_pred = clf .predict_proba (X )
106- return self ._sign * self ._score_func (y , y_pred , ** self ._kwargs )
118+ if sample_weight is not None :
119+ return self ._sign * self ._score_func (y , y_pred ,
120+ sample_weight = sample_weight ,
121+ ** self ._kwargs )
122+ else :
123+ return self ._sign * self ._score_func (y , y_pred , ** self ._kwargs )
107124
108125 def _factory_args (self ):
109126 return ", needs_proba=True"
110127
111128
112129class _ThresholdScorer (_BaseScorer ):
113- def __call__ (self , clf , X , y ):
130+ def __call__ (self , clf , X , y , sample_weight = None ):
114131 """Evaluate decision function output for X relative to y_true.
115132
116133 Parameters
@@ -128,6 +145,9 @@ def __call__(self, clf, X, y):
128145 Gold standard target values for X. These must be class labels,
129146 not decision function values.
130147
148+ sample_weight : array-like, optional (default=None)
149+ Sample weights.
150+
131151 Returns
132152 -------
133153 score : float
@@ -152,7 +172,12 @@ def __call__(self, clf, X, y):
152172 elif isinstance (y_pred , list ):
153173 y_pred = np .vstack ([p [:, - 1 ] for p in y_pred ]).T
154174
155- return self ._sign * self ._score_func (y , y_pred , ** self ._kwargs )
175+ if sample_weight is not None :
176+ return self ._sign * self ._score_func (y , y_pred ,
177+ sample_weight = sample_weight ,
178+ ** self ._kwargs )
179+ else :
180+ return self ._sign * self ._score_func (y , y_pred , ** self ._kwargs )
156181
157182 def _factory_args (self ):
158183 return ", needs_threshold=True"
0 commit comments