%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_()%3A%0A%20%20%20%20import%20polars%20as%20pl%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.compose%20import%20DecompositionPipeline%0A%20%20%20%20from%20yohou.datasets%20import%20(%0A%20%20%20%20%20%20%20%20fetch_air_quality_classification%2C%0A%20%20%20%20%20%20%20%20fetch_sunspot%2C%0A%20%20%20%20%20%20%20%20fetch_tourism_monthly%2C%0A%20%20%20%20)%0A%20%20%20%20from%20yohou.interval%20import%20SplitConformalForecaster%0A%20%20%20%20from%20yohou.model_selection%20import%20train_test_split%0A%20%20%20%20from%20yohou.plotting%20import%20(%0A%20%20%20%20%20%20%20%20plot_calibration%2C%0A%20%20%20%20%20%20%20%20plot_decomposition%2C%0A%20%20%20%20%20%20%20%20plot_forecast%2C%0A%20%20%20%20%20%20%20%20plot_time_weight%2C%0A%20%20%20%20)%0A%20%20%20%20from%20yohou.point%20import%20PointReductionForecaster%2C%20SeasonalNaive%0A%20%20%20%20from%20yohou.preprocessing%20import%20LagTransformer%0A%20%20%20%20from%20yohou.stationarity%20import%20(%0A%20%20%20%20%20%20%20%20PatternSeasonalityForecaster%2C%0A%20%20%20%20%20%20%20%20PolynomialTrendForecaster%2C%0A%20%20%20%20)%0A%20%20%20%20from%20yohou.utils.weighting%20import%20(%0A%20%20%20%20%20%20%20%20exponential_decay_weight%2C%0A%20%20%20%20%20%20%20%20linear_decay_weight%2C%0A%20%20%20%20)%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%20DecompositionPipeline%2C%0A%20%20%20%20%20%20%20%20LagTransformer%2C%0A%20%20%20%20%20%20%20%20PatternSeasonalityForecaster%2C%0A%20%20%20%20%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20%20%20%20%20PolynomialTrendForecaster%2C%0A%20%20%20%20%20%20%20%20SeasonalNaive%2C%0A%20%20%20%20%20%20%20%20SplitConformalForecaster%2C%0A%20%20%20%20%20%20%20%20exponential_decay_weight%2C%0A%20%20%20%20%20%20%20%20fetch_air_quality_classification%2C%0A%20%20%20%20%20%20%20%20fetch_sunspot%2C%0A%20%20%20%20%20%20%20%20fetch_tourism_monthly%2C%0A%20%20%20%20%20%20%20%20linear_decay_weight%2C%0A%20%20%20%20%20%20%20%20pl%2C%0A%20%20%20%20%20%20%20%20plot_calibration%2C%0A%20%20%20%20%20%20%20%20plot_decomposition%2C%0A%20%20%20%20%20%20%20%20plot_forecast%2C%0A%20%20%20%20%20%20%20%20plot_time_weight%2C%0A%20%20%20%20%20%20%20%20train_test_split%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%20Forecast%20Visualization%20and%20Comparison%0A%0A%20%20%20%20In%20this%20notebook%20we%20will%20plot%20forecasts%20from%20single%20and%20multiple%20models%2C%0A%20%20%20%20visualize%20categorical%20and%20class-probability%20predictions%2C%20check%20probability%0A%20%20%20%20calibration%2C%20inspect%20decomposition%20components%2C%20and%20render%20time%20weight%0A%20%20%20%20functions.%0A%0A%20%20%20%20%23%23%20Prerequisites%0A%0A%20%20%20%20Basic%20familiarity%20with%20yohou's%20fit%2Fpredict%20API%20(see%20%60examples%2Fquickstart.py%60).%0A%20%20%20%20%22%22%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%20Prepare%20Data%20and%20Models%0A%0A%20%20%20%20We%20load%20the%20Monthly%20Tourism%20dataset%20and%20the%20Sunspot%20dataset%2C%20then%20fit%20three%0A%20%20%20%20forecasters%3A%20%5B%60SeasonalNaive%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.point.naive.SeasonalNaive%2F)%20(repeats%20the%20last%20seasonal%20cycle)%2C%0A%20%20%20%20%5B%60PointReductionForecaster%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.point.reduction.PointReductionForecaster%2F)%20(sklearn%20regressor%20with%20lag%20features)%2C%20and%0A%20%20%20%20%5B%60SplitConformalForecaster%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.interval.split_conformal.SplitConformalForecaster%2F)%20(wraps%20a%20point%20forecaster%20to%20produce%20prediction%0A%20%20%20%20intervals%20via%20conformal%20calibration).%20Their%20predictions%20are%20reused%20across%0A%20%20%20%20all%20visualization%20sections%20below.%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%20tourism%20%3D%20(%0A%20%20%20%20%20%20%20%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%20%20%20%20)%0A%20%20%20%20fh%20%3D%2012%0A%20%20%20%20y_train%2C%20y_test%20%3D%20train_test_split(tourism%2C%20test_size%3Dfh)%0A%20%20%20%20return%20fh%2C%20y_test%2C%20y_train%0A%0A%0A%40app.cell%0Adef%20_(PointReductionForecaster%2C%20SeasonalNaive%2C%20fh%2C%20y_train)%3A%0A%20%20%20%20naive%20%3D%20SeasonalNaive(seasonality%3D12)%0A%20%20%20%20naive.fit(y_train%2C%20forecasting_horizon%3Dfh)%0A%20%20%20%20y_pred_naive%20%3D%20naive.predict(forecasting_horizon%3Dfh)%0A%0A%20%20%20%20reduction%20%3D%20PointReductionForecaster()%0A%20%20%20%20reduction.fit(y_train%2C%20forecasting_horizon%3Dfh)%0A%20%20%20%20y_pred_reduction%20%3D%20reduction.predict(forecasting_horizon%3Dfh)%0A%20%20%20%20return%20y_pred_naive%2C%20y_pred_reduction%0A%0A%0A%40app.cell%0Adef%20_(SeasonalNaive%2C%20SplitConformalForecaster%2C%20fetch_sunspot%2C%20fh)%3A%0A%20%20%20%20sunspots%20%3D%20fetch_sunspot().frame%0A%20%20%20%20ss_train%20%3D%20sunspots.head(len(sunspots)%20-%20fh)%0A%20%20%20%20ss_test%20%3D%20sunspots.tail(fh)%0A%0A%20%20%20%20conformal%20%3D%20SplitConformalForecaster(%0A%20%20%20%20%20%20%20%20point_forecaster%3DSeasonalNaive(seasonality%3D132)%2C%0A%20%20%20%20)%0A%20%20%20%20conformal.fit(ss_train%2C%20forecasting_horizon%3Dfh)%0A%20%20%20%20y_pred_conformal%20%3D%20conformal.predict_interval(%0A%20%20%20%20%20%20%20%20forecasting_horizon%3Dfh%2C%0A%20%20%20%20%20%20%20%20coverage_rates%3D%5B0.7%5D%2C%0A%20%20%20%20)%0A%20%20%20%20return%20ss_test%2C%20ss_train%2C%20y_pred_conformal%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.%20Single%20Forecast%20Plot%0A%0A%20%20%20%20%5B%60plot_forecast%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_forecast%2F)%20displays%20actuals%20vs%20predictions.%20Pass%20**y_train**%20to%20include%0A%20%20%20%20history%2C%20and%20use%20**n_history**%20to%20trim%20the%20visible%20window.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20y_pred_naive%2C%20y_test%2C%20y_train)%3A%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20y_test%2C%0A%20%20%20%20%20%20%20%20y_pred_naive%2C%0A%20%20%20%20%20%20%20%20y_train%3Dy_train%2C%0A%20%20%20%20%20%20%20%20title%3D%22Seasonal%20Naive%20-%20Full%20History%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20y_pred_naive%2C%20y_test%2C%20y_train)%3A%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20y_test%2C%0A%20%20%20%20%20%20%20%20y_pred_naive%2C%0A%20%20%20%20%20%20%20%20y_train%3Dy_train%2C%0A%20%20%20%20%20%20%20%20n_history%3D50%2C%0A%20%20%20%20%20%20%20%20title%3D%22Seasonal%20Naive%20-%20Last%2050%20Steps%20of%20History%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%202.%20Multi-Model%20Forecast%0A%0A%20%20%20%20Pass%20a%20**dict**%20of%20predictions%20to%20overlay%20multiple%20models.%20For%20interval%0A%20%20%20%20forecasters%2C%20include%20**coverage_rates**%20to%20display%20prediction%20bands.%0A%20%20%20%20Toggle%20**show_transition**%20to%20control%20the%20training%2Ftest%20boundary%20marker.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20y_pred_naive%2C%20y_pred_reduction%2C%20y_test)%3A%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20y_test%2C%0A%20%20%20%20%20%20%20%20%7B%22Naive%22%3A%20y_pred_naive%2C%20%22Reduction%22%3A%20y_pred_reduction%7D%2C%0A%20%20%20%20%20%20%20%20title%3D%22Multi-Model%20Comparison%20(Overlay)%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20ss_test%2C%20ss_train%2C%20y_pred_conformal)%3A%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20ss_test%2C%0A%20%20%20%20%20%20%20%20y_pred_conformal%2C%0A%20%20%20%20%20%20%20%20y_train%3Dss_train%2C%0A%20%20%20%20%20%20%20%20coverage_rates%3D%5B0.7%5D%2C%0A%20%20%20%20%20%20%20%20n_history%3D120%2C%0A%20%20%20%20%20%20%20%20title%3D%22Conformal%20Forecaster%20-%2070%25%20PI%20on%20Sunspot%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20y_pred_naive%2C%20y_test%2C%20y_train)%3A%0A%20%20%20%20plot_forecast(%0A%20%20%20%20%20%20%20%20y_test%2C%0A%20%20%20%20%20%20%20%20y_pred_naive%2C%0A%20%20%20%20%20%20%20%20y_train%3Dy_train%2C%0A%20%20%20%20%20%20%20%20show_transition%3DFalse%2C%0A%20%20%20%20%20%20%20%20title%3D%22Seasonal%20Naive%20-%20No%20Transition%20Marker%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%203.%20Categorical%20(Hard-Label)%20Forecasts%0A%0A%20%20%20%20%5B%60plot_forecast%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_forecast%2F)%20**auto-detects**%20columns%20with%20%60String%60%20or%20%60Categorical%60%0A%20%20%20%20dtype%20and%20renders%20a%20**step%20chart**.%20Each%20class%20is%20mapped%20to%20a%20horizontal%0A%20%20%20%20band%20so%20temporal%20transitions%20between%20categories%20are%20easy%20to%20follow.%0A%0A%20%20%20%20We%20use%20%5B%60fetch_air_quality_classification%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.datasets._fetchers.fetch_air_quality_classification%2F)%0A%20%20%20%20(4-class%20air%20quality%20target%20derived%20from%20PM2.5%20data)%20and%20fit%20a%0A%20%20%20%20%5B%60ClassProbaReductionForecaster%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.class_proba.reduction.ClassProbaReductionForecaster%2F)%0A%20%20%20%20with%20a%20%5B%60DecisionTreeClassifier%60%5D(https%3A%2F%2Fscikit-learn.org%2Fstable%2Fmodules%2Fgenerated%2Fsklearn.tree.DecisionTreeClassifier.html).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ClassProbaReductionForecaster%2C%0A%20%20%20%20DecisionTreeClassifier%2C%0A%20%20%20%20LagTransformer%2C%0A%20%20%20%20fetch_air_quality_classification%2C%0A%20%20%20%20train_test_split%2C%0A)%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%20cls_forecaster%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%2C%206%2C%2012%2C%2024%5D)%2C%0A%20%20%20%20)%0A%20%20%20%20cls_forecaster.fit(cls_y_train%2C%20cls_X_train%2C%20forecasting_horizon%3Dcls_fh)%0A%0A%20%20%20%20cls_y_pred_labels%20%3D%20cls_forecaster.predict(%0A%20%20%20%20%20%20%20%20forecasting_horizon%3Dcls_fh%2C%0A%20%20%20%20)%0A%20%20%20%20cls_y_proba%20%3D%20cls_forecaster.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%20return%20(%0A%20%20%20%20%20%20%20%20cls_X_test%2C%0A%20%20%20%20%20%20%20%20cls_fh%2C%0A%20%20%20%20%20%20%20%20cls_forecaster%2C%0A%20%20%20%20%20%20%20%20cls_y_pred_labels%2C%0A%20%20%20%20%20%20%20%20cls_y_proba%2C%0A%20%20%20%20%20%20%20%20cls_y_test%2C%0A%20%20%20%20%20%20%20%20cls_y_train%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(cls_y_pred_labels%2C%20cls_y_test%2C%20cls_y_train%2C%20plot_forecast)%3A%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%22Categorical%20Forecast%20with%20Training%20History%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%23%20Multi-Model%20Categorical%20Comparison%0A%0A%20%20%20%20Passing%20a%20**dict**%20of%20categorical%20predictions%20overlays%20step%20traces%20for%0A%20%20%20%20each%20model.%20Here%20we%20compare%20two%20rolling%20forecasts%20produced%20by%0A%20%20%20%20%60observe_predict()%60%20so%20the%20model%20updates%20its%20memory%20at%20every%20step.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20cls_X_test%2C%0A%20%20%20%20cls_fh%2C%0A%20%20%20%20cls_forecaster%2C%0A%20%20%20%20cls_y_test%2C%0A%20%20%20%20cls_y_train%2C%0A%20%20%20%20plot_forecast%2C%0A)%3A%0A%20%20%20%20cls_forecaster_obs%20%3D%20cls_forecaster%0A%20%20%20%20cls_obs_labels%20%3D%20cls_forecaster_obs.observe_predict(%0A%20%20%20%20%20%20%20%20cls_y_test%5B%3Acls_fh%5D%2C%0A%20%20%20%20%20%20%20%20X_actual%3Dcls_X_test%5B%3Acls_fh%5D%2C%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%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Static%22%3A%20cls_forecaster.predict(forecasting_horizon%3Dcls_fh)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22After%20Observe%22%3A%20cls_obs_labels%2C%0A%20%20%20%20%20%20%20%20%7D%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%22Multi-Model%20Categorical%20Comparison%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.%20Class-Probability%20(Soft)%20Forecasts%0A%0A%20%20%20%20When%20predictions%20contain%20%60_proba_%60%20columns%20(from%20%60predict_class_proba()%60)%2C%0A%20%20%20%20%5B%60plot_forecast%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_forecast%2F)%20renders%20a%20**stacked%20area%20chart**%20where%20each%20class%20is%20a%0A%20%20%20%20coloured%20band%20whose%20height%20equals%20the%20predicted%20probability.%20Diamond%0A%20%20%20%20markers%20show%20the%20true%20class%20at%20each%20time%20step.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_y_proba%2C%20cls_y_test%2C%20plot_forecast)%3A%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%22Class-Probability%20Forecast%20(Stacked%20Area)%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%23%20Reliability%20Diagram%0A%0A%20%20%20%20%5B%60plot_calibration%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.evaluation.plot_calibration%2F)%0A%20%20%20%20compares%20predicted%20probabilities%20against%20empirical%20frequencies.%20A%0A%20%20%20%20perfectly%20calibrated%20model%20follows%20the%20diagonal.%20Use%20**n_bins**%20to%0A%20%20%20%20control%20the%20number%20of%20probability%20bins.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cls_y_proba%2C%20cls_y_test%2C%20plot_calibration)%3A%0A%20%20%20%20cls_y_truth%20%3D%20cls_y_test.head(len(cls_y_proba))%0A%20%20%20%20plot_calibration(%0A%20%20%20%20%20%20%20%20cls_y_proba%2C%0A%20%20%20%20%20%20%20%20cls_y_truth%2C%0A%20%20%20%20%20%20%20%20target%3D%22air_quality%22%2C%0A%20%20%20%20%20%20%20%20n_bins%3D8%2C%0A%20%20%20%20%20%20%20%20title%3D%22Reliability%20Diagram%20-%20Air%20Quality%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%205.%20Decomposition%20Visualization%0A%0A%20%20%20%20%5B%60plot_decomposition%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_decomposition%2F)%20displays%20a%20fitted%20%5B%60DecompositionPipeline%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.compose.decomposition_pipeline.DecompositionPipeline%2F)'s%20components%0A%20%20%20%20as%20stacked%20subplots.%20Toggle%20**show_original**%20and%20pass%20a%20subset%20of%20components.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20DecompositionPipeline%2C%0A%20%20%20%20PatternSeasonalityForecaster%2C%0A%20%20%20%20PolynomialTrendForecaster%2C%0A%20%20%20%20fh%2C%0A%20%20%20%20y_train%2C%0A)%3A%0A%20%20%20%20decomp%20%3D%20DecompositionPipeline(%0A%20%20%20%20%20%20%20%20forecasters%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22trend%22%2C%20PolynomialTrendForecaster(degree%3D2))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22seasonality%22%2C%20PatternSeasonalityForecaster(seasonality%3D12))%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20store_residuals%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20decomp.fit(y_train%2C%20forecasting_horizon%3Dfh)%0A%0A%20%20%20%20decomp_components%20%3D%20%7B%7D%0A%20%20%20%20for%20_name%2C%20_fc%2C%20*_%20in%20decomp.forecasters_%3A%0A%20%20%20%20%20%20%20%20decomp_components%5B_name%5D%20%3D%20_fc.predict(forecasting_horizon%3Dfh)%0A%20%20%20%20return%20(decomp_components%2C)%0A%0A%0A%40app.cell%0Adef%20_(decomp_components%2C%20fh%2C%20plot_decomposition%2C%20y_test)%3A%0A%20%20%20%20plot_decomposition(%0A%20%20%20%20%20%20%20%20y_test.tail(fh)%2C%0A%20%20%20%20%20%20%20%20decomp_components%2C%0A%20%20%20%20%20%20%20%20show_original%3DTrue%2C%0A%20%20%20%20%20%20%20%20title%3D%22Decomposition%20-%20Trend%20%2B%20Seasonality%20with%20Original%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(decomp_components%2C%20fh%2C%20plot_decomposition%2C%20y_train)%3A%0A%20%20%20%20plot_decomposition(%0A%20%20%20%20%20%20%20%20y_train.tail(fh)%2C%0A%20%20%20%20%20%20%20%20decomp_components%2C%0A%20%20%20%20%20%20%20%20show_original%3DFalse%2C%0A%20%20%20%20%20%20%20%20title%3D%22Decomposition%20-%20Components%20Only%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(decomp_components%2C%20fh%2C%20plot_decomposition%2C%20y_test)%3A%0A%20%20%20%20plot_decomposition(%0A%20%20%20%20%20%20%20%20y_test.tail(fh)%2C%0A%20%20%20%20%20%20%20%20%7B%22trend%22%3A%20decomp_components%5B%22trend%22%5D%7D%2C%0A%20%20%20%20%20%20%20%20title%3D%22Decomposition%20-%20Trend%20Only%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.%20Time%20Weight%20Visualization%0A%0A%20%20%20%20%5B%60plot_time_weight%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.plotting.forecasting.plot_time_weight%2F)%20renders%20weighting%20functions%20over%20time.%20Toggle%20the%0A%20%20%20%20**fill**%20kwarg%20for%20an%20area%20chart%20and%20adjust%20**fill_opacity**.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(exponential_decay_weight%2C%20linear_decay_weight%2C%20pl%2C%20y_train)%3A%0A%20%20%20%20_times%20%3D%20y_train%5B%22time%22%5D%0A%20%20%20%20_exp_fn%20%3D%20exponential_decay_weight(half_life%3D24)%0A%20%20%20%20_lin_fn%20%3D%20linear_decay_weight()%0A%0A%20%20%20%20exp_weight_df%20%3D%20pl.DataFrame(%7B%22time%22%3A%20_times%2C%20%22time_weight%22%3A%20_exp_fn(_times)%7D)%0A%20%20%20%20lin_weight_df%20%3D%20pl.DataFrame(%7B%22time%22%3A%20_times%2C%20%22time_weight%22%3A%20_lin_fn(_times)%7D)%0A%20%20%20%20return%20exp_weight_df%2C%20lin_weight_df%0A%0A%0A%40app.cell%0Adef%20_(exp_weight_df%2C%20plot_time_weight)%3A%0A%20%20%20%20plot_time_weight(%0A%20%20%20%20%20%20%20%20exp_weight_df%2C%0A%20%20%20%20%20%20%20%20fill%3DTrue%2C%0A%20%20%20%20%20%20%20%20title%3D%22Exponential%20Decay%20Weight%20(half_life%3D24)%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(lin_weight_df%2C%20plot_time_weight)%3A%0A%20%20%20%20plot_time_weight(%0A%20%20%20%20%20%20%20%20lin_weight_df%2C%0A%20%20%20%20%20%20%20%20fill%3DFalse%2C%0A%20%20%20%20%20%20%20%20title%3D%22Linear%20Decay%20Weight%20-%20Line%20Only%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(lin_weight_df%2C%20plot_time_weight)%3A%0A%20%20%20%20plot_time_weight(%0A%20%20%20%20%20%20%20%20lin_weight_df%2C%0A%20%20%20%20%20%20%20%20fill%3DTrue%2C%0A%20%20%20%20%20%20%20%20fill_opacity%3D0.5%2C%0A%20%20%20%20%20%20%20%20title%3D%22Linear%20Decay%20Weight%20-%20Semi-Transparent%20Fill%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%20Next%20Steps%0A%0A%20%20%20%20-%20%5BForecast%20Visualization%5D(%2Fpages%2Ftutorials%2Fforecast-visualization%2F)%20for%20the%20full%20guide%0A%20%20%20%20-%20%5BVisualize%20Forecasts%5D(%2Fpages%2Fhow-to%2Fvisualize-forecasts%2F)%20for%20related%20techniques%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
e16f8be561c80eb30d155f4681fb4d34