Skip to content

Commit

Permalink
Merge pull request #175 from GeoDerp/master
Browse files Browse the repository at this point in the history
"perform_backtest": "false" has no effect Fix
  • Loading branch information
davidusb-geek authored Feb 4, 2024
2 parents 87d01e2 + ca1151f commit 1f6effb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/emhass/machine_learning_forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def fit(self, split_date_delta: Optional[str] = '48h', perform_backtest: Optiona
df_pred['test'] = self.data_test[self.var_model]
df_pred['pred'] = predictions
df_pred_backtest = None
if perform_backtest:
if perform_backtest is True:
# Using backtesting tool to evaluate the model
self.logger.info("Performing simple backtesting of fitted model")
start_time = time.time()
Expand Down Expand Up @@ -201,7 +201,7 @@ def predict(self, data_last_window: Optional[pd.DataFrame] = None
predictions = self.forecaster.predict(steps=self.num_lags, exog=self.data_test.drop(self.var_model, axis=1))
else:
data_last_window = data_last_window.interpolate(method='linear', axis=0, limit=None)
if self.is_tuned:
if self.is_tuned is True:
exog = MLForecaster.generate_exog(data_last_window, self.lags_opt, self.var_model)
predictions = self.forecaster.predict(steps=self.lags_opt,
last_window=data_last_window[self.var_model],
Expand All @@ -223,7 +223,7 @@ def tune(self, debug: Optional[bool] = False) -> pd.DataFrame:
"""
# Bayesian search hyperparameter and lags with skforecast/optuna
# Lags used as predictors
if debug:
if debug is True:
lags_grid = [3]
refit = False
num_lags = 3
Expand All @@ -233,7 +233,7 @@ def tune(self, debug: Optional[bool] = False) -> pd.DataFrame:
num_lags = self.num_lags
# Regressor hyperparameters search space
if self.sklearn_model == 'LinearRegression':
if debug:
if debug is True:
def search_space(trial):
search_space = {'fit_intercept': trial.suggest_categorical('fit_intercept', [True])}
return search_space
Expand All @@ -242,7 +242,7 @@ def search_space(trial):
search_space = {'fit_intercept': trial.suggest_categorical('fit_intercept', [True, False])}
return search_space
elif self.sklearn_model == 'ElasticNet':
if debug:
if debug is True:
def search_space(trial):
search_space = {'selection': trial.suggest_categorical('selection', ['random'])}
return search_space
Expand All @@ -254,7 +254,7 @@ def search_space(trial):
}
return search_space
elif self.sklearn_model == 'KNeighborsRegressor':
if debug:
if debug is True:
def search_space(trial):
search_space = {'weights': trial.suggest_categorical('weights', ['uniform'])}
return search_space
Expand Down

0 comments on commit 1f6effb

Please sign in to comment.