pyTrading
pyTrading copied to clipboard
class TimeSeriesEstimator does not fit to time series data properly with ensemble base estimators
The TimeSeriesEstimator fits to any "X" time series matrix without needing to specify a "y" target. The TimeSeriesEstimator inherents the sklearn.base.BaseEstimator class, so any sklearn.linear_model model works fine without needing the "y" target. However, the TimeSeriesEstimator does not fit properly to just an X_train matrix if the model used is from the sklearn.ensemble methods.
How can ensemble methods be also used in TimeSeriesEstimator?
model = AdaBoostRegressor()
tsr = TimeSeriesRegressor(sklearn.base.clone(model), n_prev=n_prev)
tsr.fit(X_train)
gives the error:
pyTrading/TimeSeriesEstimator.pyc in fit(self, X, Y)
107 estimator.fit(X_data, Y_data[:, i])
108 else:
--> 109 self.base_estimator.fit(X_data, Y_data)
110
111 return self
//anaconda/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.pyc in fit(self, X, y, sample_weight)
953
954 # Fit
--> 955 return super(AdaBoostRegressor, self).fit(X, y, sample_weight)
956
957 def _validate_estimator(self):
//anaconda/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.pyc in fit(self, X, y, sample_weight)
109
110 X, y = check_X_y(X, y, accept_sparse=accept_sparse, dtype=dtype,
--> 111 y_numeric=is_regressor(self))
112
113 if sample_weight is None:
//anaconda/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
513 dtype=None)
514 else:
--> 515 y = column_or_1d(y, warn=True)
516 _assert_all_finite(y)
517 if y_numeric and y.dtype.kind == 'O':
//anaconda/lib/python2.7/site-packages/sklearn/utils/validation.pyc in column_or_1d(y, warn)
549 return np.ravel(y)
550
--> 551 raise ValueError("bad input shape {0}".format(shape))
552
553
ValueError: bad input shape (3130, 218)