Skip to content

Commit

Permalink
fix: go for forecast method instead of predict in ets (#1299)
Browse files Browse the repository at this point in the history
* fix: use forecast method instead of predict

* fix: remove custom logging layer 45, defaulting to logging.INFO

* test: add unit for a smoothing+gaussian_filter+ets pipeline
  • Loading branch information
Lopa10ko committed Jun 13, 2024
1 parent d2a6785 commit ec12d26
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 1 addition & 3 deletions fedot/api/api_utils/assumptions/assumptions_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def fit_assumption_and_check_correctness(self,
pipeline.predict(data_test)
self.log.info('Initial pipeline was fitted successfully')

MemoryAnalytics.log(self.log,
additional_info='fitting of the initial pipeline',
logging_level=45) # message logging level
MemoryAnalytics.log(self.log, additional_info='fitting of the initial pipeline')

except Exception as ex:
self._raise_evaluating_exception(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,14 @@ def fit(self, input_data):

def predict(self, input_data):
input_data = copy(input_data)
idx = input_data.idx
forecast_length = input_data.task.task_params.forecast_length

start_id = idx[0]
end_id = idx[-1]
predictions = self.model.predict(start=start_id,
end=end_id)
predict = predictions
predict = np.array(predict).reshape(1, -1)
new_idx = np.arange(start_id, end_id + 1)
start_id = input_data.idx[0]
end_id = start_id + forecast_length - 1
predictions = self.model.forecast(steps=forecast_length)
predict = np.array(predictions).reshape(1, -1)

input_data.idx = new_idx
input_data.idx = np.arange(start_id, end_id)

output_data = self._convert_to_output(input_data,
predict=predict,
Expand Down
3 changes: 1 addition & 2 deletions fedot/utilities/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def finish(cls):
"""
Finish memory monitoring session
"""
cls.log(additional_info='finish',
logging_level=45) # message logging level
cls.log(additional_info='finish')
tracemalloc.stop()
cls.is_active = False

Expand Down
24 changes: 24 additions & 0 deletions test/unit/pipelines/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,30 @@ def test_ts_forecasting_pipeline_with_poly_features():
assert prediction is not None


def test_ts_forecasting_pipeline_with_ets():
""" Test for an ets-comprising pipeline, ensuring predict does not contain NaNs """
smoothing_node = PipelineNode('smoothing')
smoothing_node.parameters = {'window_size': 9}
gaussian_filter_node = PipelineNode('gaussian_filter', nodes_from=[smoothing_node])
smoothing_node.parameters = {'sigma': 4.747037682823521}
ets_node = PipelineNode('ets', nodes_from=[gaussian_filter_node])
ets_node.parameters = {
'error': 'mul',
'trend': 'mul',
'seasonal': 'add',
'damped_trend': False,
'seasonal_periods': 37
}
pipeline = Pipeline(ets_node)

train_data, test_data = get_ts_data(n_steps=450, forecast_length=30)

pipeline.fit(train_data)
prediction = pipeline.predict(test_data)
assert prediction is not None
assert not np.isnan(prediction.predict).any()


def test_get_nodes_with_operation():
pipeline = pipeline_first()
actual_nodes = pipeline.get_nodes_by_name(name='rf')
Expand Down

0 comments on commit ec12d26

Please sign in to comment.