Skip to content

Commit

Permalink
Refactor forecast stats wrappers.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxjohn committed Mar 11, 2022
1 parent 35c2290 commit 9033414
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions hyperts/framework/wrappers/stats_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def fit(self, X, y=None, **kwargs):

def predict(self, X, **kwargs):
last_date = X[self.timestamp].tail(1).to_list()[0].to_pydatetime()
if last_date == self._end_date:
raise ValueError('The end date of the valid set must be '
'less than the end date of the test set.')
steps = int((last_date - self._end_date).total_seconds() / self._freq)
predict_result = self.model.forecast(steps=steps).values

Expand Down Expand Up @@ -120,6 +123,9 @@ def fit(self, X, y=None, **kwargs):

def predict(self, X, **kwargs):
last_date = X[self.timestamp].tail(1).to_list()[0].to_pydatetime()
if last_date == self._end_date:
raise ValueError('The end date of the valid set must be '
'less than the end date of the test set.')
steps = int((last_date - self._end_date).total_seconds() / self._freq)
predict_result = self.model.forecast(self.model.y, steps=steps)

Expand Down
6 changes: 3 additions & 3 deletions hyperts/tests/experiment/task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_univariate_forecast(self):
optimize_direction=OptimizeDirection.Minimize)
hyper_model = HyperTS(rs, task='univariate-forecast', reward_metric='rmse', callbacks=[SummaryCallback()])

exp = TSCompeteExperiment(hyper_model, X_train, y_train, X_eval=X_test, y_eval=y_test,
exp = TSCompeteExperiment(hyper_model, X_train, y_train,
timestamp_col='ds',
covariate_cols=[['id'], cs.covariables_],
covariate_cleaner=cs)
Expand All @@ -46,7 +46,7 @@ def test_multivariate_forecast(self):
optimize_direction=OptimizeDirection.Minimize)
hyper_model = HyperTS(rs, task='multivariate-forecast', reward_metric='rmse', callbacks=[SummaryCallback()])

exp = TSCompeteExperiment(hyper_model, X_train, y_train, X_eval=X_test, y_eval=y_test, timestamp_col='ds')
exp = TSCompeteExperiment(hyper_model, X_train, y_train, timestamp_col='ds')
pipeline_model = exp.run(max_trials=3)

y_pred = pipeline_model.predict(X_test)
Expand All @@ -60,7 +60,7 @@ def test_univariate_classification(self):
optimize_direction=OptimizeDirection.Maximize)
hyper_model = HyperTS(rs, task='univariate-multiclass', reward_metric='accuracy', callbacks=[SummaryCallback()])

exp = TSCompeteExperiment(hyper_model, X_train, y_train, X_eval=X_test, y_eval=y_test)
exp = TSCompeteExperiment(hyper_model, X_train, y_train)
pipeline_model = exp.run(max_trials=3)

y_pred = pipeline_model.predict(X_test)
Expand Down

0 comments on commit 9033414

Please sign in to comment.