Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sporadic forecasting test failure #1280

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,24 @@ class ExpSmoothingImplementation(ModelImplementation):
def __init__(self, params: OperationParameters):
super().__init__(params)
self.model = None
if self.params.get("seasonal"):
self.seasonal_periods = int(self.params.get("seasonal_periods"))
if self.params.get('seasonal'):
self.seasonal_periods = int(self.params.get('seasonal_periods'))
else:
self.seasonal_periods = None

def fit(self, input_data):
endog = input_data.features.astype('float64')

# check ets params according to statsmodels restrictions
self._check_and_correct_params(endog)
self.log.info(f'Changed the following ETSModel parameters: {self.params.changed_parameters}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше сделать так:

if self._check_and_correct_params(endog) # need to change return statement
        self.log.info(f'Changed the following ETSModel parameters: {self.params.changed_parameters}')

Чтобы не вводить юзера в заблуждение, что параметры меняются (а они могут и не поменяться)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


self.model = ETSModel(
input_data.features.astype("float64"),
error=self.params.get("error"),
trend=self.params.get("trend"),
seasonal=self.params.get("seasonal"),
damped_trend=self.params.get("damped_trend") if self.params.get("trend") else None,
endog=endog,
error=self.params.get('error'),
trend=self.params.get('trend'),
seasonal=self.params.get('seasonal'),
damped_trend=self.params.get('damped_trend') if self.params.get('trend') else None,
seasonal_periods=self.seasonal_periods
)
self.model = self.model.fit(disp=False)
Expand Down Expand Up @@ -312,3 +318,16 @@ def predict_for_fit(self, input_data: InputData) -> OutputData:
predict=predict,
data_type=DataTypesEnum.table)
return output_data

def _check_and_correct_params(self, endog: np.ndarray) -> None:
ets_components = ['error', 'trend', 'seasonal']
if any(self.params.get(component) == 'mul' for component in ets_components):
if np.any(endog <= 0):
for component in ets_components:
if self.params.get(component) == 'mul':
self.params.update(**{f'{component}': 'add'})

if self.params.get('trend') == 'mul' \
and self.params.get('damped_trend') \
and not self.params.get('seasonal'):
self.params.update(trend='add')
2 changes: 1 addition & 1 deletion fedot/core/pipelines/tuning/search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_parameters_dict(self):
'type': 'categorical'},
'seasonal_periods': {
'hyperopt-dist': hp.uniform,
'sampling-scope': [1, 100],
'sampling-scope': [2, 100],
'type': 'continuous'}
},
'glm': {
Expand Down
Loading