66
77import numpy as np
88import scipy .sparse as sp
9+ import warnings
910
1011from ..externals .joblib import Parallel , delayed
1112
@@ -222,8 +223,7 @@ def _set_class_weight(self, class_weight, classes, y):
222223
223224 self ._expanded_class_weight = weight
224225
225- def _partial_fit (self , X , y , n_iter , classes = None ,
226- class_weight = None , sample_weight = None ):
226+ def _partial_fit (self , X , y , n_iter , classes = None , sample_weight = None ):
227227 X = safe_asarray (X , dtype = np .float64 , order = "C" )
228228 y = np .asarray (y )
229229
@@ -243,7 +243,7 @@ def _partial_fit(self, X, y, n_iter, classes=None,
243243 n_classes = self .classes_ .shape [0 ]
244244
245245 # Allocate datastructures from input arguments
246- self ._set_class_weight (class_weight , self .classes_ , y )
246+ self ._set_class_weight (self . class_weight , self .classes_ , y )
247247 sample_weight = self ._validate_sample_weight (sample_weight , n_samples )
248248
249249 if self .coef_ is None :
@@ -283,16 +283,6 @@ def partial_fit(self, X, y, classes=None,
283283 and can be omitted in the subsequent calls.
284284 Note that y doesn't need to contain all labels in `classes`.
285285
286- class_weight : dict, {class_label : weight} or "auto"
287- Weights associated with classes.
288-
289- The "auto" mode uses the values of y to automatically adjust
290- weights inversely proportional to class frequencies.
291-
292- If None, values defined in the previous call to partial_fit
293- will be used. If partial_fit was never called before,
294- uniform weights are assumed.
295-
296286 sample_weight : array-like, shape = [n_samples], optional
297287 Weights applied to individual samples.
298288 If not provided, uniform weights are assumed.
@@ -301,8 +291,12 @@ def partial_fit(self, X, y, classes=None,
301291 -------
302292 self : returns an instance of self.
303293 """
294+ if class_weight != None :
295+ warnings .warn ("Using 'class_weight' as a parameter to the 'fit'"
296+ "method is deprecated. Set it on initialization instead." ,
297+ DeprecationWarning )
298+ self .class_weight = class_weight
304299 return self ._partial_fit (X , y , n_iter = 1 , classes = classes ,
305- class_weight = class_weight ,
306300 sample_weight = sample_weight )
307301
308302 def fit (self , X , y , coef_init = None , intercept_init = None ,
@@ -323,13 +317,6 @@ def fit(self, X, y, coef_init=None, intercept_init=None,
323317 intercept_init : array, shape = [n_classes]
324318 The initial intercept to warm-start the optimization.
325319
326- class_weight : dict, {class_label : weight} or "auto"
327- Weights associated with classes. If not given, all classes
328- are supposed to have weight one.
329-
330- The "auto" mode uses the values of y to automatically adjust
331- weights inversely proportional to class frequencies.
332-
333320 sample_weight : array-like, shape = [n_samples], optional
334321 Weights applied to individual samples.
335322 If not provided, uniform weights are assumed.
@@ -338,6 +325,11 @@ def fit(self, X, y, coef_init=None, intercept_init=None,
338325 -------
339326 self : returns an instance of self.
340327 """
328+ if class_weight != None :
329+ warnings .warn ("Using 'class_weight' as a parameter to the 'fit'"
330+ "method is deprecated. Set it on initialization instead." ,
331+ DeprecationWarning )
332+ self .class_weight = class_weight
341333 X = safe_asarray (X , dtype = np .float64 , order = "C" )
342334 y = np .asarray (y )
343335
@@ -363,8 +355,7 @@ def fit(self, X, y, coef_init=None, intercept_init=None,
363355
364356 self ._partial_fit (X , y , self .n_iter ,
365357 classes = classes ,
366- sample_weight = sample_weight ,
367- class_weight = class_weight )
358+ sample_weight = sample_weight )
368359
369360 # fitting is over, we can now transform coef_ to fortran order
370361 # for faster predictions
0 commit comments