%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22scikit-learn%22%2C%0A%23%20%20%20%20%20%22yohou%5Bplotting%5D%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.23.8%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Hyperparameter%20Search%20for%20Time%20Series%0A%0A%20%20%20%20Yohou's%20%5B%60GridSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.search.GridSearchCV%2F)%20and%20%5B%60RandomizedSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.search.RandomizedSearchCV%2F)%20combine%20sklearn's%20hyperparameter%0A%20%20%20%20search%20with%20time-respecting%20cross-validation.%20They%20work%20with%20any%20forecaster%2C%0A%20%20%20%20scorer%2C%20and%20splitter.%0A%0A%20%20%20%20**Prerequisites%3A**%20Familiarity%20with%20splitters%20(see%20%60cv_splitters.py%60)%20and%20scorers%20(see%20%60metrics%2F%60).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20from%20copy%20import%20deepcopy%0A%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20from%20scipy.stats%20import%20uniform%0A%20%20%20%20from%20sklearn.linear_model%20import%20Ridge%0A%20%20%20%20from%20sklearn.tree%20import%20DecisionTreeClassifier%0A%0A%20%20%20%20from%20yohou.class_proba%20import%20ClassProbaReductionForecaster%0A%20%20%20%20from%20yohou.datasets%20import%20fetch_air_quality_classification%2C%20fetch_tourism_monthly%0A%20%20%20%20from%20yohou.metrics%20import%20LogLoss%2C%20MeanAbsoluteError%0A%20%20%20%20from%20yohou.model_selection%20import%20(%0A%20%20%20%20%20%20%20%20ExpandingWindowSplitter%2C%0A%20%20%20%20%20%20%20%20GridSearchCV%2C%0A%20%20%20%20%20%20%20%20RandomizedSearchCV%2C%0A%20%20%20%20%20%20%20%20train_test_split%2C%0A%20%20%20%20)%0A%20%20%20%20from%20yohou.plotting%20import%20(%0A%20%20%20%20%20%20%20%20plot_cv_results_scatter%2C%0A%20%20%20%20%20%20%20%20plot_forecast%2C%0A%20%20%20%20%20%20%20%20plot_score_per_step%2C%0A%20%20%20%20%20%20%20%20plot_time_series%2C%0A%20%20%20%20)%0A%20%20%20%20from%20yohou.point%20import%20PointReductionForecaster%0A%20%20%20%20from%20yohou.preprocessing%20import%20LagTransformer%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20ClassProbaReductionForecaster%2C%0A%20%20%20%20%20%20%20%20DecisionTreeClassifier%2C%0A%20%20%20%20%20%20%20%20ExpandingWindowSplitter%2C%0A%20%20%20%20%20%20%20%20GridSearchCV%2C%0A%20%20%20%20%20%20%20%20LagTransformer%2C%0A%20%20%20%20%20%20%20%20LogLoss%2C%0A%20%20%20%20%20%20%20%20MeanAbsoluteError%2C%0A%20%20%20%20%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20%20%20%20%20RandomizedSearchCV%2C%0A%20%20%20%20%20%20%20%20Ridge%2C%0A%20%20%20%20%20%20%20%20deepcopy%2C%0A%20%20%20%20%20%20%20%20fetch_air_quality_classification%2C%0A%20%20%20%20%20%20%20%20fetch_tourism_monthly%2C%0A%20%20%20%20%20%20%20%20pl%2C%0A%20%20%20%20%20%20%20%20plot_cv_results_scatter%2C%0A%20%20%20%20%20%20%20%20plot_forecast%2C%0A%20%20%20%20%20%20%20%20plot_score_per_step%2C%0A%20%20%20%20%20%20%20%20plot_time_series%2C%0A%20%20%20%20%20%20%20%20train_test_split%2C%0A%20%20%20%20%20%20%20%20uniform%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201.%20Setup%0A%0A%20%20%20%20We%20load%20the%20data%20and%20define%20the%20forecaster%2C%20parameter%20grid%2C%20and%20cross-validation%20splitter%20used%20throughout%20the%20search%20examples.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fetch_tourism_monthly%2C%20train_test_split)%3A%0A%0A%20%20%20%20y%20%3D%20fetch_tourism_monthly().frame.select(%22time%22%2C%20%22T1__tourists%22).drop_nulls().rename(%7B%22T1__tourists%22%3A%20%22tourists%22%7D)%0A%0A%20%20%20%20y_train%2C%20y_test%20%3D%20train_test_split(y%2C%20test_size%3D24)%0A%20%20%20%20fh%20%3D%2012%0A%0A%20%20%20%20print(f%22Train%3A%20%7Blen(y_train)%7D%2C%20Test%3A%20%7Blen(y_test)%7D%2C%20Horizon%3A%20%7Bfh%7D%22)%0A%20%20%20%20return%20fh%2C%20y%2C%20y_test%2C%20y_train%0A%0A%0A%40app.cell%0Adef%20_(plot_time_series%2C%20y)%3A%0A%20%20%20%20plot_time_series(y%2C%20title%3D%22Tourism%20Monthly%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%202.%20GridSearchCV%0A%0A%20%20%20%20Exhaustive%20grid%20search%20over%20parameter%20combinations.%0A%20%20%20%20Uses%20%5B%60ExpandingWindowSplitter%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.split.ExpandingWindowSplitter%2F)%20for%20temporal%20CV%20and%20%5B%60MeanAbsoluteError%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.metrics.point.MeanAbsoluteError%2F)%20for%20scoring.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExpandingWindowSplitter%2C%0A%20%20%20%20GridSearchCV%2C%0A%20%20%20%20LagTransformer%2C%0A%20%20%20%20MeanAbsoluteError%2C%0A%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20Ridge%2C%0A%20%20%20%20fh%2C%0A%20%20%20%20y_train%2C%0A)%3A%0A%20%20%20%20base_fc%20%3D%20PointReductionForecaster(%0A%20%20%20%20%20%20%20%20estimator%3DRidge()%2C%0A%20%20%20%20%20%20%20%20feature_transformer%3DLagTransformer(lag%3Dlist(range(1%2C%207)))%2C%0A%20%20%20%20)%0A%0A%20%20%20%20grid_search%20%3D%20GridSearchCV(%0A%20%20%20%20%20%20%20%20forecaster%3Dbase_fc%2C%0A%20%20%20%20%20%20%20%20param_grid%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22estimator__alpha%22%3A%20%5B0.01%2C%200.1%2C%201.0%2C%2010.0%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22feature_transformer__lag%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20list(range(1%2C%207))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20list(range(1%2C%2013))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20scoring%3DMeanAbsoluteError()%2C%0A%20%20%20%20%20%20%20%20cv%3DExpandingWindowSplitter(n_splits%3D2%2C%20test_size%3Dfh)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20grid_search.fit(y_train%2C%20forecasting_horizon%3Dfh)%0A%0A%20%20%20%20print(f%22Best%20params%3A%20%7Bgrid_search.best_params_%7D%22)%0A%20%20%20%20print(f%22Best%20score%3A%20%20%7Bgrid_search.best_score_%3A.2f%7D%22)%0A%20%20%20%20return%20(grid_search%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%203.%20Inspecting%20Results%0A%0A%20%20%20%20%60cv_results_%60%20is%20a%20dict%20with%20per-parameter-combination%20scores%2C%20similar%20to%20sklearn.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(grid_search%2C%20pl)%3A%0A%20%20%20%20cv_results%20%3D%20grid_search.cv_results_%0A%20%20%20%20results_df%20%3D%20pl.DataFrame(%7B%0A%20%20%20%20%20%20%20%20%22params%22%3A%20%5Bstr(p)%20for%20p%20in%20cv_results%5B%22params%22%5D%5D%2C%0A%20%20%20%20%20%20%20%20%22mean_test_score%22%3A%20cv_results%5B%22mean_test_score%22%5D%2C%0A%20%20%20%20%20%20%20%20%22rank_test_score%22%3A%20cv_results%5B%22rank_test_score%22%5D%2C%0A%20%20%20%20%7D).sort(%22rank_test_score%22)%0A%0A%20%20%20%20results_df%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%5B%60plot_cv_results_scatter%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.model_selection.plot_cv_results_scatter%2F)%20plots%20each%20parameter%20combination%20against%20its%0A%20%20%20%20mean%20test%20score%2C%20showing%20how%20performance%20varies%20across%20the%20grid.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(grid_search%2C%20plot_cv_results_scatter)%3A%0A%20%20%20%20plot_cv_results_scatter(%0A%20%20%20%20%20%20%20%20grid_search.cv_results_%2C%0A%20%20%20%20%20%20%20%20param_name%3D%22estimator__alpha%22%2C%0A%20%20%20%20%20%20%20%20title%3D%22Grid%20Search%3A%20Alpha%20vs%20Score%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204.%20Predict%20with%20Best%20Model%0A%0A%20%20%20%20After%20fitting%2C%20%5B%60GridSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.search.GridSearchCV%2F)%20acts%20as%20a%20forecaster%20using%20the%20best-found%20parameters.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(MeanAbsoluteError%2C%20grid_search%2C%20y_test%2C%20y_train)%3A%0A%20%20%20%20y_pred%20%3D%20grid_search.predict(forecasting_horizon%3Dlen(y_test))%0A%0A%20%20%20%20mae%20%3D%20MeanAbsoluteError()%0A%20%20%20%20mae.fit(y_train)%0A%20%20%20%20score%20%3D%20mae.score(y_test%2C%20y_pred)%0A%20%20%20%20print(f%22Best%20model%20MAE%20on%20test%3A%20%7Bscore%3A.2f%7D%22)%0A%20%20%20%20y_pred.head()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%205.%20RandomizedSearchCV%0A%0A%20%20%20%20For%20larger%20search%20spaces%2C%20%5B%60RandomizedSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.search.RandomizedSearchCV%2F)%20samples%20parameter%20combinations%0A%20%20%20%20randomly.%20Use%20%60n_iter%60%20to%20control%20how%20many%20to%20try.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExpandingWindowSplitter%2C%0A%20%20%20%20LagTransformer%2C%0A%20%20%20%20MeanAbsoluteError%2C%0A%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20RandomizedSearchCV%2C%0A%20%20%20%20Ridge%2C%0A%20%20%20%20fh%2C%0A%20%20%20%20uniform%2C%0A%20%20%20%20y_train%2C%0A)%3A%0A%20%20%20%20rand_search%20%3D%20RandomizedSearchCV(%0A%20%20%20%20%20%20%20%20forecaster%3DPointReductionForecaster(%0A%20%20%20%20%20%20%20%20%20%20%20%20estimator%3DRidge()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20feature_transformer%3DLagTransformer(lag%3Dlist(range(1%2C%207)))%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20param_distributions%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22estimator__alpha%22%3A%20uniform(loc%3D0.01%2C%20scale%3D20)%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20n_iter%3D8%2C%0A%20%20%20%20%20%20%20%20scoring%3DMeanAbsoluteError()%2C%0A%20%20%20%20%20%20%20%20cv%3DExpandingWindowSplitter(n_splits%3D2%2C%20test_size%3Dfh)%2C%0A%20%20%20%20%20%20%20%20random_state%3D42%2C%0A%20%20%20%20)%0A%0A%20%20%20%20rand_search.fit(y_train%2C%20forecasting_horizon%3Dfh)%0A%20%20%20%20print(f%22Best%20params%3A%20%7Brand_search.best_params_%7D%22)%0A%20%20%20%20print(f%22Best%20score%3A%20%20%7Brand_search.best_score_%3A.2f%7D%22)%0A%20%20%20%20return%20(rand_search%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%5B%60plot_cv_results_scatter%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.model_selection.plot_cv_results_scatter%2F)%20visualises%20the%20randomly%20sampled%20alpha%20values%0A%20%20%20%20against%20their%20mean%20test%20scores.%20The%20more%20dispersed%20distribution%20compared%0A%20%20%20%20to%20the%20grid%20search%20illustrates%20how%20randomised%20search%20explores%20the%20space.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_cv_results_scatter%2C%20rand_search)%3A%0A%20%20%20%20plot_cv_results_scatter(%0A%20%20%20%20%20%20%20%20rand_search.cv_results_%2C%0A%20%20%20%20%20%20%20%20param_name%3D%22estimator__alpha%22%2C%0A%20%20%20%20%20%20%20%20title%3D%22Randomized%20Search%3A%20Alpha%20vs%20Score%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%206.%20GridSearchCV%20for%20Classification%0A%0A%20%20%20%20%5B%60GridSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.model_selection.search.GridSearchCV%2F)%20works%20identically%20with%20class-probability%20forecasters.%0A%20%20%20%20Pass%20a%20classification%20scorer%20such%20as%20%5B%60LogLoss%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.metrics.class_proba.LogLoss%2F)%20and%20search%20over%20the%0A%20%20%20%20classifier%20and%20feature%20transformer%20hyperparameters.%20We%20use%20the%0A%20%20%20%20%5B%60fetch_air_quality_classification%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.datasets._fetchers.fetch_air_quality_classification%2F)%0A%20%20%20%20dataset%20(4-class%20air%20quality%20target%2C%205%20pollutant%20features).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fetch_air_quality_classification%2C%20train_test_split)%3A%0A%20%20%20%20cls_data%20%3D%20fetch_air_quality_classification()%0A%20%20%20%20cls_y%2C%20cls_X%20%3D%20cls_data.y%2C%20cls_data.X_actual%0A%20%20%20%20cls_y_train%2C%20cls_y_test%2C%20cls_X_train%2C%20cls_X_test%20%3D%20train_test_split(%0A%20%20%20%20%20%20%20%20cls_y%2C%0A%20%20%20%20%20%20%20%20cls_X%2C%0A%20%20%20%20%20%20%20%20test_size%3D200%2C%0A%20%20%20%20)%0A%20%20%20%20cls_fh%20%3D%2024%0A%0A%20%20%20%20print(f%22Classes%3A%20%7Bcls_data.classes%7D%22)%0A%20%20%20%20print(f%22Train%3A%20%7Blen(cls_y_train)%7D%2C%20Test%3A%20%7Blen(cls_y_test)%7D%2C%20Horizon%3A%20%7Bcls_fh%7D%22)%0A%20%20%20%20return%20cls_X_train%2C%20cls_fh%2C%20cls_y_test%2C%20cls_y_train%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ClassProbaReductionForecaster%2C%0A%20%20%20%20DecisionTreeClassifier%2C%0A%20%20%20%20ExpandingWindowSplitter%2C%0A%20%20%20%20GridSearchCV%2C%0A%20%20%20%20LagTransformer%2C%0A%20%20%20%20LogLoss%2C%0A%20%20%20%20cls_X_train%2C%0A%20%20%20%20cls_fh%2C%0A%20%20%20%20cls_y_train%2C%0A)%3A%0A%20%20%20%20cls_base%20%3D%20ClassProbaReductionForecaster(%0A%20%20%20%20%20%20%20%20estimator%3DDecisionTreeClassifier(random_state%3D42)%2C%0A%20%20%20%20%20%20%20%20feature_transformer%3DLagTransformer(lag%3D%5B1%2C%202%2C%203%5D)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20cls_grid_search%20%3D%20GridSearchCV(%0A%20%20%20%20%20%20%20%20forecaster%3Dcls_base%2C%0A%20%20%20%20%20%20%20%20param_grid%3D%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22estimator__max_depth%22%3A%20%5B3%2C%205%2C%2010%2C%20None%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22feature_transformer__lag%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B1%2C%202%2C%203%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B1%2C%202%2C%203%2C%206%2C%2012%2C%2024%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20scoring%3DLogLoss()%2C%0A%20%20%20%20%20%20%20%20cv%3DExpandingWindowSplitter(n_splits%3D2%2C%20test_size%3Dcls_fh)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20cls_grid_search.fit(cls_y_train%2C%20cls_X_train%2C%20forecasting_horizon%3Dcls_fh)%0A%0A%20%20%20%20print(f%22Best%20params%3A%20%7Bcls_grid_search.best_params_%7D%22)%0A%20%20%20%20print(f%22Best%20LogLoss%3A%20%7Bcls_grid_search.best_score_%3A.4f%7D%22)%0A%20%20%20%20return%20(cls_grid_search%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%207.%20Inspecting%20Classification%20Search%20Results%0A%0A%20%20%20%20The%20%60cv_results_%60%20dict%20contains%20per-combination%20scores%20just%20like%20the%0A%20%20%20%20point%20forecaster%20search.%20%5B%60plot_cv_results_scatter%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.model_selection.plot_cv_results_scatter%2F)%20works%20with%20any%0A%20%20%20%20parameter%20name%20from%20the%20grid.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_grid_search%2C%20pl)%3A%0A%20%20%20%20cls_cv_results%20%3D%20cls_grid_search.cv_results_%0A%20%20%20%20cls_results_df%20%3D%20pl.DataFrame(%7B%0A%20%20%20%20%20%20%20%20%22params%22%3A%20%5Bstr(p)%20for%20p%20in%20cls_cv_results%5B%22params%22%5D%5D%2C%0A%20%20%20%20%20%20%20%20%22mean_test_score%22%3A%20cls_cv_results%5B%22mean_test_score%22%5D%2C%0A%20%20%20%20%20%20%20%20%22rank_test_score%22%3A%20cls_cv_results%5B%22rank_test_score%22%5D%2C%0A%20%20%20%20%7D).sort(%22rank_test_score%22)%0A%0A%20%20%20%20cls_results_df%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_grid_search%2C%20plot_cv_results_scatter)%3A%0A%20%20%20%20plot_cv_results_scatter(%0A%20%20%20%20%20%20%20%20cls_grid_search.cv_results_%2C%0A%20%20%20%20%20%20%20%20param_name%3D%22estimator__max_depth%22%2C%0A%20%20%20%20%20%20%20%20title%3D%22Classification%20Grid%20Search%3A%20max_depth%20vs%20LogLoss%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%208.%20Predict%20with%20Best%20Classification%20Model%0A%0A%20%20%20%20After%20fitting%2C%20the%20search%20object%20exposes%20both%20%60predict()%60%20(hard%20labels)%0A%20%20%20%20and%20%60predict_class_proba()%60%20(soft%20probabilities).%20%5B%60plot_forecast%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_forecast%2F)%0A%20%20%20%20auto-detects%20the%20prediction%20type%20and%20renders%20step%20charts%20for%20categorical%0A%20%20%20%20data%20and%20stacked%20area%20charts%20for%20class%20probabilities.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_fh%2C%20cls_grid_search%2C%20cls_y_test%2C%20cls_y_train%2C%20plot_forecast)%3A%0A%20%20%20%20cls_y_pred_labels%20%3D%20cls_grid_search.predict(%0A%20%20%20%20%20%20%20%20forecasting_horizon%3Dcls_fh%2C%0A%20%20%20%20)%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20cls_y_test%2C%0A%20%20%20%20%20%20%20%20cls_y_pred_labels%2C%0A%20%20%20%20%20%20%20%20y_train%3Dcls_y_train%2C%0A%20%20%20%20%20%20%20%20n_history%3D50%2C%0A%20%20%20%20%20%20%20%20title%3D%22Best%20Model%20-%20Hard-Label%20Forecast%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_fh%2C%20cls_grid_search%2C%20cls_y_test%2C%20plot_forecast)%3A%0A%20%20%20%20cls_y_proba%20%3D%20cls_grid_search.predict_class_proba(%0A%20%20%20%20%20%20%20%20forecasting_horizon%3Dcls_fh%2C%0A%20%20%20%20)%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20cls_y_test%2C%0A%20%20%20%20%20%20%20%20cls_y_proba%2C%0A%20%20%20%20%20%20%20%20title%3D%22Best%20Model%20-%20Class-Probability%20Forecast%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Multi-vintage%20Scoring%0A%0A%20%20%20%20The%20%60observe_predict%60%20method%20with%20%60stride%3D1%60%20produces%20one%20forecast%20per%0A%20%20%20%20observation%20point%2C%20creating%20multiple%20*vintages*.%20Each%20vintage%20represents%0A%20%20%20%20a%20different%20forecast%20origin%2C%20so%20you%20can%20analyse%20how%20accuracy%20evolves%20as%0A%20%20%20%20the%20model%20absorbs%20more%20data.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(deepcopy%2C%20fh%2C%20grid_search%2C%20y%2C%20y_train)%3A%0A%20%20%20%20_vintage_model%20%3D%20deepcopy(grid_search.best_forecaster_)%0A%20%20%20%20y_after_train%20%3D%20y.slice(len(y_train))%0A%20%20%20%20y_pred_vintages%20%3D%20_vintage_model.observe_predict(%0A%20%20%20%20%20%20%20%20y%3Dy_after_train%2C%0A%20%20%20%20%20%20%20%20forecasting_horizon%3Dfh%2C%0A%20%20%20%20)%0A%20%20%20%20print(f%22Vintages%3A%20%7By_pred_vintages%5B'vintage_time'%5D.n_unique()%7D%22)%0A%20%20%20%20y_pred_vintages.head(10)%0A%20%20%20%20return%20y_after_train%2C%20y_pred_vintages%0A%0A%0A%40app.cell%0Adef%20_(MeanAbsoluteError%2C%20y_train)%3A%0A%20%20%20%20vintage_scorer%20%3D%20MeanAbsoluteError()%0A%20%20%20%20vintage_scorer.fit(y_train)%0A%20%20%20%20return%20(vintage_scorer%2C)%0A%0A%0A%40app.cell%0Adef%20_(plot_score_per_step%2C%20vintage_scorer%2C%20y_after_train%2C%20y_pred_vintages)%3A%0A%20%20%20%20plot_score_per_step(%0A%20%20%20%20%20%20%20%20vintage_scorer%2C%0A%20%20%20%20%20%20%20%20y_after_train%2C%0A%20%20%20%20%20%20%20%20y_pred_vintages%2C%0A%20%20%20%20%20%20%20%20title%3D%22MAE%20per%20Forecast%20Step%22%2C%0A%20%20%20%20%20%20%20%20y_label%3D%22MAE%22%2C%0A%20%20%20%20%20%20%20%20height%3D380%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Next%20Steps%0A%0A%20%20%20%20-%20**Splitters**%3A%20See%20%5B%60cv_splitters.py%60%5D(%2Fexamples%2Fgetting-started%2Fcv_splitters%2F)%20for%20splitter%20details%0A%20%20%20%20-%20**Scoring**%3A%20See%20%5BMetrics%5D(%2Fexamples%2F%23metrics)%20for%20all%20available%20scorers%0A%20%20%20%20-%20**Interval%20search**%3A%20Use%20%5B%60IntervalReductionForecaster%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.interval.reduction.IntervalReductionForecaster%2F)%20with%20search%20for%20interval%20tuning%0A%20%20%20%20-%20**Classification%20forecaster**%3A%20See%20%5B%60class_proba_forecaster.py%60%5D(%2Fexamples%2Fpoint%2Fclass_proba_forecaster%2F)%20for%20the%20full%20classification%20workflow%0A%20%20%20%20-%20**Classification%20metrics**%3A%20See%20%5B%60class_proba_metrics.py%60%5D(%2Fexamples%2Fevaluation-search%2Fclass_proba_metrics%2F)%20for%20LogLoss%2C%20BrierScore%2C%20and%20Accuracy%20evaluation%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
2e82e03f4e48312afcf4ea78909e7d8e