def test_predict_ts_with_not_X_index(ts_data): X, y = ts_data X = X.reset_index(drop=True) assert not isinstance(X.index, pd.DatetimeIndex) m_clf = ARIMARegressor() clf_ = m_clf.fit(X=X, y=y) with pytest.raises( ValueError, match= "If not it will look for the datetime column in the index of X."): clf_.predict(X)
def test_fit_predict_ts_with_X_and_y_index(mock_get_dates, mock_format_dates, ts_data_seasonal): X, y = ts_data_seasonal assert isinstance(X.index, pd.DatetimeIndex) assert isinstance(y.index, pd.DatetimeIndex) mock_get_dates.return_value = (X.index, X) mock_format_dates.return_value = (X, y, None) fh_ = forecasting.ForecastingHorizon(y.index, is_relative=False) a_clf = sktime_arima.AutoARIMA() clf = a_clf.fit(X=X, y=y) y_pred_sk = clf.predict(fh=fh_, X=X) m_clf = ARIMARegressor(d=None) m_clf.fit(X=X, y=y) mock_format_dates.return_value = (X, y, fh_) y_pred = m_clf.predict(X=X) assert (y_pred_sk == y_pred.to_series()).all()
def test_fit_predict_ts_with_X_and_y_index(ts_data): X, y = ts_data assert isinstance(X.index, pd.DatetimeIndex) assert isinstance(y.index, pd.DatetimeIndex) a_clf = arima.ARIMA(endog=y, exog=X, order=(1, 0, 0), trend='n', dates=X.index) clf = a_clf.fit() y_pred_a = clf.predict() m_clf = ARIMARegressor(p=1, d=0, q=0) clf_ = m_clf.fit(X=X, y=y) y_pred = clf_.predict(X=X) assert (y_pred == y_pred_a).all()
def test_fit_predict_date_col_named(ts_data): X, y = ts_data a_clf = arima.ARIMA(endog=y, exog=X, order=(1, 0, 0), trend='n', dates=X.index) clf = a_clf.fit() y_pred_a = clf.predict(params=(1, 0, 0)) X = X.reset_index() assert not isinstance(X.index, pd.DatetimeIndex) m_clf = ARIMARegressor(p=1, d=0, q=0, date_column='index') clf_ = m_clf.fit(X=X, y=y) y_pred = clf_.predict(X=X, y=y) assert (y_pred == y_pred_a).all()
def test_fit_predict_date_index_named_out_of_sample(X_none, ts_data_seasonal): X, y = ts_data_seasonal fh_ = forecasting.ForecastingHorizon(y[250:].index, is_relative=False) a_clf = sktime_arima.AutoARIMA() if X_none: clf = a_clf.fit(y=y[:250]) y_pred_sk = clf.predict(fh=fh_) else: clf = a_clf.fit(X=X[:250], y=y[:250]) y_pred_sk = clf.predict(fh=fh_, X=X[250:]) X = X.reset_index() assert not isinstance(X.index, pd.DatetimeIndex) m_clf = ARIMARegressor(date_index='index', d=None) if X_none: m_clf.fit(X=None, y=y[:250]) y_pred = m_clf.predict(X=None, y=y[250:]) else: m_clf.fit(X=X[:250], y=y[:250]) y_pred = m_clf.predict(X=X[250:], y=y[250:]) assert (y_pred_sk.to_period('D') == y_pred.to_series()).all()
def test_fit_predict_ts_with_y_not_X_index_with_iterable_p_and_q(ts_data): X, y = ts_data a_clf = arima.ARIMA(endog=y, exog=X, order=([1, 2], 0, [1, 2]), trend='n', dates=X.index) clf = a_clf.fit() y_pred_a = clf.predict(params=(1, 0, 0)) X_no_ind = X.reset_index(drop=True) assert isinstance(y.index, pd.DatetimeIndex) assert not isinstance(X_no_ind.index, pd.DatetimeIndex) m_clf = ARIMARegressor(p=[1, 2], d=0, q=[1, 2]) clf_ = m_clf.fit(X=X_no_ind, y=y) y_pred = clf_.predict(X=X, y=y) assert (y_pred == y_pred_a).all()
def test_feature_importance(ts_data): X, y = ts_data clf = ARIMARegressor() clf.fit(X, y) clf.feature_importance == np.zeros(1)
def test_fit_ts_without_y(ts_data): X, y = ts_data clf = ARIMARegressor(p=1, d=0, q=0) with pytest.raises(ValueError, match="ARIMA Regressor requires y as input."): clf.fit(X=X)
def test_model_instance(ts_data): X, y = ts_data clf = ARIMARegressor() fitted = clf.fit(X, y) assert isinstance(fitted, ARIMARegressor)