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

prediction intervals added #1063

Closed
wants to merge 2 commits into from

Conversation

GrigoriJasnovidov
Copy link
Collaborator

@GrigoriJasnovidov GrigoriJasnovidov commented Mar 7, 2023

ConfidenceIntervals class for predicting confidence intervals is created.
The instance of ConfidenceInterval class takes pipelines from the last generation, fit these pipelines in order to minimize quantile_loss metric and creates confidence intervals in this way.

ConfidenceIntervals(model, train_input)
Arguments:
model - a fitted fedot model for ts_forecasting.
train_input – a train input used for building the model.
Methods:
.fit(up_quantile, low_quantile,horizon=None,low_tuner=None,up_tuner=None,number_models=10,pipelines_show =
True)
This method outputs several confidence intervals allowing us to build a final confidence interval using method forecast.
Arguments:
up_quantile/low_quantile – quantiles for upper/low confidence intervals.
horizon – length of time horizon for predicting confidence intervals. If None then it is the same as in
model.task.params; if natural number this number of steps is used for forecasting.
number_models – number models used for forecasting confidence intervals. Can be natural number or ‘max’, in
this case all avaliable models used. If number_models > number of avaliable models then all avaliable
models used.

   		     pipelines_show – boolean parameters whether to show pipelines during fitting.  

.forecast(regim = ‘quantile’) forecasts confidence intervals given ConfidenceIntervals fitted. Possible values of regime:
‘quantile’,’median’, etc. In each regime intervals obtained after fitting are used to build confidence intervals
.plot() plot the confidence intervals, forecast and (if given) actual test time series

@codecov
Copy link

codecov bot commented Mar 7, 2023

Codecov Report

Merging #1063 (ab3f401) into master (35281f6) will decrease coverage by 10.95%.
Report is 38 commits behind head on master.
The diff coverage is 73.95%.

❗ Current head ab3f401 differs from pull request most recent head d821935. Consider uploading reports for the commit d821935 to get more accurate results

@@             Coverage Diff             @@
##           master    #1063       +/-   ##
===========================================
- Coverage   88.22%   77.28%   -10.95%     
===========================================
  Files         130      146       +16     
  Lines        9311    10100      +789     
===========================================
- Hits         8215     7806      -409     
- Misses       1096     2294     +1198     
Files Changed Coverage Δ
fedot/api/api_utils/api_data.py 64.17% <0.00%> (-23.89%) ⬇️
...t/api/api_utils/assumptions/assumptions_handler.py 86.00% <ø> (ø)
...edot/api/api_utils/assumptions/task_assumptions.py 77.19% <ø> (-1.76%) ⬇️
fedot/api/fedot_cli.py 0.00% <ø> (-86.89%) ⬇️
fedot/core/operations/data_operation.py 93.75% <ø> (-0.37%) ⬇️
fedot/core/operations/evaluation/custom.py 54.16% <ø> (-41.67%) ⬇️
...implementations/data_operations/text_pretrained.py 41.30% <0.00%> (-19.57%) ⬇️
fedot/core/operations/evaluation/time_series.py 96.42% <ø> (ø)
...t/core/repository/pipeline_operation_repository.py 96.96% <ø> (-0.09%) ⬇️
...intervals/solvers/last_generation_quantile_loss.py 18.75% <18.75%> (ø)
... and 48 more

... and 51 files with indirect coverage changes

@nicl-nno
Copy link
Collaborator

nicl-nno commented Mar 7, 2023

Прежде чем буду содержательно смотреть:

  1. Убрать лишние файлы
  2. Пояснить как собственно это все использовать - где точка входа.

Добавить к одному из имеющихся примеров прогнозирования Fedot-ом интервальную оценку.

@nicl-nno
Copy link
Collaborator

  1. По примерам - с самом FEDOT-е такое количество ноутбуков не нужно, добавь хватит одного примера в формате .py.
    На каком-то наиболее показательном датасете.

  2. Нужен хотя бы базовый unit-тест, показывающий что всё это работает.

  3. Много отступлений от PEP8 - проверь плз.

Comment on lines 12 to 23
class Quantile_Loss_low(QualityMetric):
default_value = sys.maxsize
@staticmethod
def metric(reference: InputData, predicted: OutputData) -> float:
value = quantile_loss(reference.target, predicted.predict,quantile = low_quantile)
return value
class Quantile_Loss_up(QualityMetric):
default_value = sys.maxsize
@staticmethod
def metric(reference: InputData, predicted: OutputData) -> float:
value = quantile_loss(reference.target, predicted.predict,quantile = up_quantile)
return value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если есть модуль metrics - то можно их туда и отправить.

from fedot.confidence_intervals.visualization import plot_confidence_intervals
from fedot.core.repository.tasks import Task,TaskTypesEnum,TsForecastingParams

class ConfidenceIntervals:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Логика класса в целом понятна, но нужно его доработать, причем больше в сторону упрощения. Сейчас он делает очень много всего за раз.

При этом класс жестко реализует только один способ построение интервалов - хотя явно нужна вариативность, чтобы реализовать и другие методы.

Cтруктурно класс и другие связанные с ним стоит положить в fedot/fedot/core/pipelines/ts/confidence_interval, например - не в корень FEDOT-а.

@aim-pep8-bot
Copy link

aim-pep8-bot commented Apr 14, 2023

Hello @GrigoriJasnovidov! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 3:1: F403 'from fedot import ' used; unable to detect undefined names
Line 3:1: F401 'fedot.
' imported but unused
Line 4:1: F401 'fedot.version.version' imported but unused

Line 22:121: E501 line too long (122 > 120 characters)

Line 26:121: E501 line too long (132 > 120 characters)

Line 10:1: F403 'from fedot.core.pipelines.automl_wrappers import *' used; unable to detect undefined names
Line 54:16: F405 'H2OSerializationWrapper' may be undefined, or defined from star imports: fedot.core.pipelines.automl_wrappers
Line 94:28: F405 'H2OSerializationWrapper' may be undefined, or defined from star imports: fedot.core.pipelines.automl_wrappers
Line 113:88: E226 missing whitespace around arithmetic operator
Line 118:16: F405 'H2OSerializationWrapper' may be undefined, or defined from star imports: fedot.core.pipelines.automl_wrappers
Line 180:17: F405 'TPOTRegressionSerializationWrapper' may be undefined, or defined from star imports: fedot.core.pipelines.automl_wrappers

Comment last updated at 2023-08-17 15:28:50 UTC

@GrigoriJasnovidov GrigoriJasnovidov changed the title confidence intervals added prediction intervals added Apr 17, 2023
Copy link
Collaborator

@valer1435 valer1435 left a comment

Choose a reason for hiding this comment

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

Сильно не хватает Docstring и TypeHint

fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/metrics.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@valer1435 valer1435 left a comment

Choose a reason for hiding this comment

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

Нужно обновить примеры под новый интерфейс + стоит добавить пример в .py формате, по аналогии с api_forecasting, например

fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
fedot/prediction_intervals/main.py Outdated Show resolved Hide resolved
@valer1435
Copy link
Collaborator

valer1435 commented Jun 14, 2023

Еще по поводу ноутбуков: я не то, чтобы с интервалами много работал, но то, что я видел, обычно визуализируется заливкой в плотлибе. Делается это не очень просто (когда-то сам делал), но так понятнее, чем смотреть на n графиков, которые сливаются в единое целое. Тот вариант, что сейчас точно нужно оставить, но вариант с заливкой кмк приятнее глазу и не нагружает (пример ниже).

image
image

И еще в ноутбуках очень много как будто лишнего вывода (нужно долго скроллить)

@nicl-nno
Copy link
Collaborator

Перед вливанием ветки причесанные ноутбуки можно будет перенести сюда как один из примеров: https://github.com/ITMO-NSS-team/fedot-examples

Copy link
Collaborator

@valer1435 valer1435 left a comment

Choose a reason for hiding this comment

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

Пример в .py файле и переработка ноутбуков еще не готовы? Кстати примеры можно перенести в папку examples/simple/ts/confidence_intervals

PS можно делать ссылки на код, где делаешь исправления, например, так:

from fedot.prediction_intervals.solvers.mutation_of_best_pipeline import solver_mutation_of_best_pipeline


def solver_prediction_intervals(model,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Можно ли это сделать через partial? С первого взгляда выглядит, что да

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

сделано

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

добавил примеры

@valer1435 valer1435 self-requested a review June 26, 2023 04:57
Copy link
Collaborator

@valer1435 valer1435 left a comment

Choose a reason for hiding this comment

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

Уезжаю на сборы, поменял вердикт, чтобы смог влить

@nicl-nno
Copy link
Collaborator

Замечания позакрывал, осталось синхронизировать с мастером.

deleted redundant files

corrected typos

simplifeid code

remove redundant

correct pep8 issues

add example

add mutations

correct visualization fiting process

improve visualization

add partial in solver.py

add example in .py format

examples/confidence_intervals

move prediction intervals in core/pipelines

delete old examples

add unit tests

Refactoring of ApiParams and ApiMetrics (aimclub#1041)

* WIP refactor ApiParams

* Remove explicit ApiParams initialization

* Move all params initialization to ApiParams

* Minor changes

* Remove _divide_params

* WIP create ApiParamsBuilder

* Add ApiParamsBuilder

* Minor

* Rename history_folder to history_dir

* Remove train_data from ApiParams

* Fixes after rebase

* Move obtain_metric to ApiMetrics

* Fix plot_pareto

* Fix Fedot.tune

* Refactor Fedot.get_metrics

* Fix Fedot.tune

* Fix metric names

* Fixes after rebase

* Remove ApiParamsBuilder

* Structure parameters in Fedot docstring

* Refactor init_composer_requirements

* Refactor init_optimizer_params

* Refactor init_optimizer_params

* Fix docstrings

* Add tests for ApiParamsRepository

* Minors

* Fix test_api_params

* Review fixes

* Review fixes

* Review fixes

Hotfix of pipeline import export example (aimclub#1064)

meta rules  (aimclub#1057)

* initial assumption

* final architecture

* add meta rules

* minor

* simplify

* add meta rule

* fix with cv folds

* minors

* fix types

* minor

* golem fixes

* add log messages

* pep8

* remove log file

Fix initial assumptions as list of pipelines (aimclub#1070)

`Fedot(..., initial_assumption=...)` is expected to get a sequence of pipelines and pass them as initial graphs to an optimizer via composer.

Moreover, FEDOT itself generates more than one initial assumption by default.

As the result of this bug, composer passed only one of the initial assumptions to an optimizer.

This PR fixes the bug and adds the corresponding test.

tests fix (aimclub#1073)

* remove some assumptions

* update requirements

* fix pep8

* update to golem

Docs updated, badges added (aimclub#1072)

* Docs updated, badges added

* Mirror workflow fix

Improve API documentation (aimclub#1067)

- Moved type hints from method headers to corresponding parameters.

- Allowed referencing GOLEM objects in FEDOT documentation.

- Replaced all url links to documentation pages with sphinx references - it fixed some broken links.

- FEDOT now uses its own directory for cache, instead of using GOLEM folder.

- Documented `**composer_tuner_params` of `Fedot` with type hints and default values.

All parameters with no usage examples are placed to the separate issue aimclub#1076

minor meta fix (aimclub#1078)

* minor fix

* indent fix

* minor

Add catboost to default initial assumptions (aimclub#1081)

* add catboost to default initial assumptions for classification

* restrict mutating loss function in CatBoost

* evaluate f1 as expected in the example

* pep8

F1 averaging fix (aimclub#1083)

Minor logging fix (aimclub#1082)

* fix print instead of logging for memory consumption

1059 timestamp bug (aimclub#1065)

879 FEDOT features (aimclub#1075)

describe framework's features

add example for surrogate optimizer (aimclub#1085)

Example with surrogate optimizer was added. External parameters field was removed from api (now we should use partial)

related pull request in GOLEM aimclub/GOLEM#82

has_one_root fix (aimclub#1091)

* has_one_root fix

* test fix

Remove outdated test handled in thegolem (aimclub#1101)

358 Reduce execution time for unit tests (aimclub#1098)

Update RTD benchmarks tabular data page (aimclub#1099)

* +csv support

Golem update requirements (aimclub#1088)

* Upd RemoveType in Advisor (golem sync)

* Upd requirements.txt for stable GOLEM

* Fix few imports

Add ts bench (aimclub#1104)

Add results from ts benchmark

Release 0.7.1 and test workflow updates (aimclub#1105)

* Upd release version

* Add pre-release tests actions on 'release' branch; Disable auto-publish

* Upd GOLEM version

* Remove manual-build.yml (dup of integration-build.yml)

* Add integration tests badge to README

* Revert "Upd GOLEM version" (for PR in master)

This reverts commit 257ff16.

Hotfix some integration tests for release 071 (aimclub#1107)

* Fix integration test of ApiParams

* Fix integration test of composition_time

* Fix integration test of metocean_forecasting

* Fix integration test of nemo_multiple.py

* Workaround for sqlite exception raised in tests

* pep8 fixes

* fix different seed in quality imporvement tests

* simplify condition

* remove test that barely tested anything

* fix condition

* remove seed from example

* fix typo

parallel cache files test fix (aimclub#1109)

Add IOptTuner (aimclub#1102)

* Refactor search space

* Fix ParametersChanges

* Redact tuner builder

* PEP 8

* Fix examples and correct tuning docs

* Add IOpt example to docs

* Add simple IOpt example

* Fix integration tests (6 steal not work)

* Fix integration test test_tuner_builder_with_custom_params (6 steal not work)

* Fix pep8

* Add tuners comparison in docs

* Update golem version in requirements

* Fix warn_requirements

* Fix warn_requirements

* Fix table in tuning docs

* Fix credit_scoring_problem_multiobj.py

* Fix extra requirements

* Edit docs

* Fix table in docs

* Change requirements

* Test requirements

* Set stable branch

+ h2o benchmark's tabular data values  (aimclub#1106)

* +h2o vals

* change csv to html

* specified table uuid

* change max values style

* add df to html converter

---------

Co-authored-by: nicl-nno <[email protected]>

Added results for multimodal benchmark into FEDOT.docs (aimclub#1115)

* - added results for multimodal benchmark

...

add docstrings and type hints

add prediction intervals unit test

simplified solvers code

correct pep issues

add class defining PredictionIntervals params

fix MutationStrength import issue

correct test_data path

update imports

updated unit tests

correct type-hint

small corrections

take short ts for unit test

update pred_int test

change ql_models to 'max' in pred_ints test

update params for ql method

...

update example

update tests

add base_quantiles visualization

fix import get_base_quantiles

update examples and deleted ql from tests

update

pep

pep issues

pep

pep

update requirements.txt
@nicl-nno
Copy link
Collaborator

Replaced with #1149

@nicl-nno nicl-nno closed this Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants