3535from ..base import ClassifierMixin
3636from ..base import RegressorMixin
3737from ..utils import check_random_state , check_array , check_X_y , column_or_1d
38- from ..utils import check_consistent_length
38+ from ..utils import check_consistent_length , deprecated
3939from ..utils .extmath import logsumexp
4040from ..utils .fixes import expit , bincount
4141from ..utils .stats import _weighted_percentile
@@ -438,7 +438,7 @@ class ClassificationLossFunction(six.with_metaclass(ABCMeta, LossFunction)):
438438 def _score_to_proba (self , score ):
439439 """Template method to convert scores to probabilities.
440440
441- If the loss does not support probabilites raises AttributeError.
441+ the does not support probabilites raises AttributeError.
442442 """
443443 raise TypeError ('%s does not support predict_proba' % type (self ).__name__ )
444444
@@ -1044,9 +1044,10 @@ def _fit_stages(self, X, y, y_pred, sample_weight, random_state,
10441044 self .train_score_ [i ] = loss_ (y [sample_mask ],
10451045 y_pred [sample_mask ],
10461046 sample_weight [sample_mask ])
1047- self .oob_improvement_ [i ] = (old_oob_score -
1048- loss_ (y [~ sample_mask ], y_pred [~ sample_mask ],
1049- sample_weight [~ sample_mask ]))
1047+ self .oob_improvement_ [i ] = (
1048+ old_oob_score - loss_ (y [~ sample_mask ],
1049+ y_pred [~ sample_mask ],
1050+ sample_weight [~ sample_mask ]))
10501051 else :
10511052 # no need to fancy index w/ no subsampling
10521053 self .train_score_ [i ] = loss_ (y , y_pred , sample_weight )
@@ -1082,6 +1083,7 @@ def _decision_function(self, X):
10821083 predict_stages (self .estimators_ , X , self .learning_rate , score )
10831084 return score
10841085
1086+ @deprecated (" and will be removed in 0.19" )
10851087 def decision_function (self , X ):
10861088 """Compute the decision function of ``X``.
10871089
@@ -1104,7 +1106,7 @@ def decision_function(self, X):
11041106 return score .ravel ()
11051107 return score
11061108
1107- def staged_decision_function (self , X ):
1109+ def _staged_decision_function (self , X ):
11081110 """Compute decision function of ``X`` for each iteration.
11091111
11101112 This method allows monitoring (i.e. determine error on testing set)
@@ -1129,6 +1131,30 @@ def staged_decision_function(self, X):
11291131 predict_stage (self .estimators_ , i , X , self .learning_rate , score )
11301132 yield score .copy ()
11311133
1134+ @deprecated (" and will be removed in 0.19" )
1135+ def staged_decision_function (self , X ):
1136+ """Compute decision function of ``X`` for each iteration.
1137+
1138+ This method allows monitoring (i.e. determine error on testing set)
1139+ after each stage.
1140+
1141+ Parameters
1142+ ----------
1143+ X : array-like of shape = [n_samples, n_features]
1144+ The input samples.
1145+
1146+ Returns
1147+ -------
1148+ score : generator of array, shape = [n_samples, k]
1149+ The decision function of the input samples. The order of the
1150+ classes corresponds to that in the attribute `classes_`.
1151+ Regression and binary classification are special cases with
1152+ ``k == 1``, otherwise ``k==n_classes``.
1153+ """
1154+ for dec in self ._staged_decision_function (X ):
1155+ # no yield from in Python2.X
1156+ yield dec
1157+
11321158 @property
11331159 def feature_importances_ (self ):
11341160 """Return the feature importances (the higher, the more important the
@@ -1315,6 +1341,51 @@ def _validate_y(self, y):
13151341 self .n_classes_ = len (self .classes_ )
13161342 return y
13171343
1344+ def decision_function (self , X ):
1345+ """Compute the decision function of ``X``.
1346+
1347+ Parameters
1348+ ----------
1349+ X : array-like of shape = [n_samples, n_features]
1350+ The input samples.
1351+
1352+ Returns
1353+ -------
1354+ score : array, shape = [n_samples, n_classes] or [n_samples]
1355+ The decision function of the input samples. The order of the
1356+ classes corresponds to that in the attribute `classes_`.
1357+ Regression and binary classification produce an array of shape
1358+ [n_samples].
1359+ """
1360+ X = check_array (X , dtype = DTYPE , order = "C" )
1361+ score = self ._decision_function (X )
1362+ if score .shape [1 ] == 1 :
1363+ return score .ravel ()
1364+ return score
1365+
1366+ def staged_decision_function (self , X ):
1367+ """Compute decision function of ``X`` for each iteration.
1368+
1369+ This method allows monitoring (i.e. determine error on testing set)
1370+ after each stage.
1371+
1372+ Parameters
1373+ ----------
1374+ X : array-like of shape = [n_samples, n_features]
1375+ The input samples.
1376+
1377+ Returns
1378+ -------
1379+ score : generator of array, shape = [n_samples, k]
1380+ The decision function of the input samples. The order of the
1381+ classes corresponds to that in the attribute `classes_`.
1382+ Regression and binary classification are special cases with
1383+ ``k == 1``, otherwise ``k==n_classes``.
1384+ """
1385+ for dec in self ._staged_decision_function (X ):
1386+ # no yield from in Python2.X
1387+ yield dec
1388+
13181389 def predict (self , X ):
13191390 """Predict class for X.
13201391
@@ -1348,7 +1419,7 @@ def staged_predict(self, X):
13481419 y : generator of array of shape = [n_samples]
13491420 The predicted value of the input samples.
13501421 """
1351- for score in self .staged_decision_function (X ):
1422+ for score in self ._staged_decision_function (X ):
13521423 decisions = self .loss_ ._score_to_decision (score )
13531424 yield self .classes_ .take (decisions , axis = 0 )
13541425
@@ -1419,7 +1490,7 @@ def staged_predict_proba(self, X):
14191490 The predicted value of the input samples.
14201491 """
14211492 try :
1422- for score in self .staged_decision_function (X ):
1493+ for score in self ._staged_decision_function (X ):
14231494 yield self .loss_ ._score_to_proba (score )
14241495 except NotFittedError :
14251496 raise
@@ -1594,7 +1665,8 @@ def predict(self, X):
15941665 y : array of shape = [n_samples]
15951666 The predicted values.
15961667 """
1597- return self .decision_function (X ).ravel ()
1668+ X = check_array (X , dtype = DTYPE , order = "C" )
1669+ return self ._decision_function (X ).ravel ()
15981670
15991671 def staged_predict (self , X ):
16001672 """Predict regression target at each stage for X.
@@ -1612,5 +1684,5 @@ def staged_predict(self, X):
16121684 y : generator of array of shape = [n_samples]
16131685 The predicted value of the input samples.
16141686 """
1615- for y in self .staged_decision_function (X ):
1687+ for y in self ._staged_decision_function (X ):
16161688 yield y .ravel ()
0 commit comments