@@ -197,32 +197,32 @@ def fit(self, X_train, y_train, budget=None, **kwargs):
197
197
train_time = self ._fit (X_train , y_train , ** kwargs )
198
198
return train_time
199
199
200
- def predict (self , X_test ):
200
+ def predict (self , X ):
201
201
"""Predict label from features.
202
202
203
203
Args:
204
- X_test : A numpy array or a dataframe of featurized instances, shape n*m.
204
+ X : A numpy array or a dataframe of featurized instances, shape n*m.
205
205
206
206
Returns:
207
207
A numpy array of shape n*1.
208
208
Each element is the label for a instance.
209
209
"""
210
210
if self ._model is not None :
211
- X_test = self ._preprocess (X_test )
212
- return self ._model .predict (X_test )
211
+ X = self ._preprocess (X )
212
+ return self ._model .predict (X )
213
213
else :
214
214
logger .warning (
215
215
"Estimator is not fit yet. Please run fit() before predict()."
216
216
)
217
- return np .ones (X_test .shape [0 ])
217
+ return np .ones (X .shape [0 ])
218
218
219
- def predict_proba (self , X_test ):
219
+ def predict_proba (self , X ):
220
220
"""Predict the probability of each class from features.
221
221
222
222
Only works for classification problems
223
223
224
224
Args:
225
- X_test : A numpy array of featurized instances, shape n*m.
225
+ X : A numpy array of featurized instances, shape n*m.
226
226
227
227
Returns:
228
228
A numpy array of shape n*c. c is the # classes.
@@ -231,8 +231,8 @@ class j.
231
231
"""
232
232
assert self ._task in CLASSIFICATION , "predict_proba() only for classification."
233
233
234
- X_test = self ._preprocess (X_test )
235
- return self ._model .predict_proba (X_test )
234
+ X = self ._preprocess (X )
235
+ return self ._model .predict_proba (X )
236
236
237
237
def cleanup (self ):
238
238
del self ._model
@@ -708,18 +708,18 @@ def _init_model_for_predict(self, X_test):
708
708
)
709
709
return test_dataset , training_args
710
710
711
- def predict_proba (self , X_test ):
711
+ def predict_proba (self , X ):
712
712
assert (
713
713
self ._task in CLASSIFICATION
714
714
), "predict_proba() only for classification tasks."
715
715
716
- test_dataset , _ = self ._init_model_for_predict (X_test )
716
+ test_dataset , _ = self ._init_model_for_predict (X )
717
717
predictions = self ._trainer .predict (test_dataset )
718
718
self ._trainer = None
719
719
return predictions .predictions
720
720
721
- def predict (self , X_test ):
722
- test_dataset , training_args = self ._init_model_for_predict (X_test )
721
+ def predict (self , X ):
722
+ test_dataset , training_args = self ._init_model_for_predict (X )
723
723
if self ._task not in NLG_TASKS :
724
724
predictions = self ._trainer .predict (test_dataset )
725
725
else :
@@ -1108,12 +1108,12 @@ def fit(self, X_train, y_train, budget=None, **kwargs):
1108
1108
train_time = time .time () - start_time
1109
1109
return train_time
1110
1110
1111
- def predict (self , X_test ):
1111
+ def predict (self , X ):
1112
1112
import xgboost as xgb
1113
1113
1114
- if not issparse (X_test ):
1115
- X_test = self ._preprocess (X_test )
1116
- dtest = xgb .DMatrix (X_test )
1114
+ if not issparse (X ):
1115
+ X = self ._preprocess (X )
1116
+ dtest = xgb .DMatrix (X )
1117
1117
return super ().predict (dtest )
1118
1118
1119
1119
@classmethod
@@ -1598,22 +1598,22 @@ def fit(self, X_train, y_train, budget=None, **kwargs):
1598
1598
self ._model = model
1599
1599
return train_time
1600
1600
1601
- def predict (self , X_test ):
1602
- if isinstance (X_test , int ):
1601
+ def predict (self , X ):
1602
+ if isinstance (X , int ):
1603
1603
raise ValueError (
1604
1604
"predict() with steps is only supported for arima/sarimax."
1605
1605
" For Prophet, pass a dataframe with the first column containing"
1606
1606
" the timestamp values."
1607
1607
)
1608
1608
if self ._model is not None :
1609
- X_test = self ._preprocess (X_test )
1610
- forecast = self ._model .predict (X_test )
1609
+ X = self ._preprocess (X )
1610
+ forecast = self ._model .predict (X )
1611
1611
return forecast ["yhat" ]
1612
1612
else :
1613
1613
logger .warning (
1614
1614
"Estimator is not fit yet. Please run fit() before predict()."
1615
1615
)
1616
- return np .ones (X_test .shape [0 ])
1616
+ return np .ones (X .shape [0 ])
1617
1617
1618
1618
1619
1619
class ARIMA (Prophet ):
@@ -1678,30 +1678,30 @@ def fit(self, X_train, y_train, budget=None, **kwargs):
1678
1678
self ._model = model
1679
1679
return train_time
1680
1680
1681
- def predict (self , X_test ):
1681
+ def predict (self , X ):
1682
1682
if self ._model is not None :
1683
- if isinstance (X_test , int ):
1684
- forecast = self ._model .forecast (steps = X_test )
1685
- elif isinstance (X_test , DataFrame ):
1686
- start = X_test [TS_TIMESTAMP_COL ].iloc [0 ]
1687
- end = X_test [TS_TIMESTAMP_COL ].iloc [- 1 ]
1688
- if len (X_test .columns ) > 1 :
1689
- X_test = self ._preprocess (X_test .drop (columns = TS_TIMESTAMP_COL ))
1690
- regressors = list (X_test )
1691
- print (start , end , X_test .shape )
1683
+ if isinstance (X , int ):
1684
+ forecast = self ._model .forecast (steps = X )
1685
+ elif isinstance (X , DataFrame ):
1686
+ start = X [TS_TIMESTAMP_COL ].iloc [0 ]
1687
+ end = X [TS_TIMESTAMP_COL ].iloc [- 1 ]
1688
+ if len (X .columns ) > 1 :
1689
+ X = self ._preprocess (X .drop (columns = TS_TIMESTAMP_COL ))
1690
+ regressors = list (X )
1691
+ print (start , end , X .shape )
1692
1692
forecast = self ._model .predict (
1693
- start = start , end = end , exog = X_test [regressors ]
1693
+ start = start , end = end , exog = X [regressors ]
1694
1694
)
1695
1695
else :
1696
1696
forecast = self ._model .predict (start = start , end = end )
1697
1697
else :
1698
1698
raise ValueError (
1699
- "X_test needs to be either a pandas Dataframe with dates as the first column"
1699
+ "X needs to be either a pandas Dataframe with dates as the first column"
1700
1700
" or an int number of periods for predict()."
1701
1701
)
1702
1702
return forecast
1703
1703
else :
1704
- return np .ones (X_test if isinstance (X_test , int ) else X_test .shape [0 ])
1704
+ return np .ones (X if isinstance (X , int ) else X .shape [0 ])
1705
1705
1706
1706
1707
1707
class SARIMAX (ARIMA ):
@@ -1873,42 +1873,40 @@ def fit(self, X_train, y_train, budget=None, **kwargs):
1873
1873
train_time = time .time () - current_time
1874
1874
return train_time
1875
1875
1876
- def predict (self , X_test ):
1876
+ def predict (self , X ):
1877
1877
if self ._model is not None :
1878
- X_test = self .transform_X (X_test )
1879
- X_test = self ._preprocess (X_test )
1878
+ X = self .transform_X (X )
1879
+ X = self ._preprocess (X )
1880
1880
if isinstance (self ._model , list ):
1881
1881
assert len (self ._model ) == len (
1882
- X_test
1883
- ), "Model is optimized for horizon, length of X_test must be equal to `period`."
1882
+ X
1883
+ ), "Model is optimized for horizon, length of X must be equal to `period`."
1884
1884
preds = []
1885
1885
for i in range (1 , len (self ._model ) + 1 ):
1886
1886
(
1887
1887
X_pred ,
1888
1888
_ ,
1889
1889
) = self .hcrystaball_model ._transform_data_to_tsmodel_input_format (
1890
- X_test .iloc [:i , :]
1890
+ X .iloc [:i , :]
1891
1891
)
1892
1892
preds .append (self ._model [i - 1 ].predict (X_pred )[- 1 ])
1893
1893
forecast = DataFrame (
1894
1894
data = np .asarray (preds ).reshape (- 1 , 1 ),
1895
1895
columns = [self .hcrystaball_model .name ],
1896
- index = X_test .index ,
1896
+ index = X .index ,
1897
1897
)
1898
1898
else :
1899
1899
(
1900
1900
X_pred ,
1901
1901
_ ,
1902
- ) = self .hcrystaball_model ._transform_data_to_tsmodel_input_format (
1903
- X_test
1904
- )
1902
+ ) = self .hcrystaball_model ._transform_data_to_tsmodel_input_format (X )
1905
1903
forecast = self ._model .predict (X_pred )
1906
1904
return forecast
1907
1905
else :
1908
1906
logger .warning (
1909
1907
"Estimator is not fit yet. Please run fit() before predict()."
1910
1908
)
1911
- return np .ones (X_test .shape [0 ])
1909
+ return np .ones (X .shape [0 ])
1912
1910
1913
1911
1914
1912
class LGBM_TS_Regressor (TS_SKLearn_Regressor ):
0 commit comments