%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%20Interval%20Forecasting%0A%0A%20%20%20%20In%20this%20notebook%2C%20we%20will%20wrap%20a%20point%20forecaster%20with%0A%20%20%20%20%5B%60SplitConformalForecaster%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou.interval.split_conformal.SplitConformalForecaster%2F)%0A%20%20%20%20to%20produce%20prediction%20intervals%20with%20coverage%20guarantees%20for%20continuous%0A%20%20%20%20targets.%20The%20split%20conformal%20method%20reserves%20a%20calibration%20set%20to%20estimate%0A%20%20%20%20residual%20quantiles%2C%20then%20constructs%20intervals%20guaranteed%20to%20contain%20future%0A%20%20%20%20observations%20at%20the%20target%20rate%20as%20calibration%20data%20grows.%0A%0A%20%20%20%20**Prerequisites%3A**%20Completed%20%5BGetting%20Started%5D(%2Fpages%2Ftutorials%2Fgetting-started%2F).%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%20sklearn.linear_model%20import%20Ridge%0A%0A%20%20%20%20from%20yohou.compose%20import%20FeaturePipeline%0A%20%20%20%20from%20yohou.datasets%20import%20fetch_tourism_monthly%0A%20%20%20%20from%20yohou.interval%20import%20SplitConformalForecaster%0A%20%20%20%20from%20yohou.metrics%20import%20EmpiricalCoverage%0A%20%20%20%20from%20yohou.plotting%20import%20plot_forecast%0A%20%20%20%20from%20yohou.point%20import%20PointReductionForecaster%0A%20%20%20%20from%20yohou.preprocessing%20import%20LagTransformer%0A%20%20%20%20from%20yohou.stationarity%20import%20SeasonalDifferencing%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20EmpiricalCoverage%2C%0A%20%20%20%20%20%20%20%20FeaturePipeline%2C%0A%20%20%20%20%20%20%20%20LagTransformer%2C%0A%20%20%20%20%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20%20%20%20%20Ridge%2C%0A%20%20%20%20%20%20%20%20SeasonalDifferencing%2C%0A%20%20%20%20%20%20%20%20SplitConformalForecaster%2C%0A%20%20%20%20%20%20%20%20fetch_tourism_monthly%2C%0A%20%20%20%20%20%20%20%20plot_forecast%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.%20Load%20and%20Setup%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fetch_tourism_monthly)%3A%0A%20%20%20%20from%20yohou.model_selection%20import%20train_test_split%0A%0A%20%20%20%20bunch%20%3D%20fetch_tourism_monthly()%0A%20%20%20%20y%20%3D%20(%0A%20%20%20%20%20%20%20%20bunch.frame%0A%20%20%20%20%20%20%20%20.select(%22time%22%2C%20%22T1__tourists%22)%0A%20%20%20%20%20%20%20%20.rename(%7B%22T1__tourists%22%3A%20%22tourists%22%7D)%0A%20%20%20%20%20%20%20%20.drop_nulls()%0A%20%20%20%20)%0A%20%20%20%20forecasting_horizon%20%3D%2012%0A%20%20%20%20y_train%2C%20y_test%20%3D%20train_test_split(y%2C%20test_size%3Dforecasting_horizon)%0A%20%20%20%20print(f%22Series%3A%20%7Blen(y)%7D%20months%20%20%7C%20%20Train%3A%20%7Blen(y_train)%7D%20%20%7C%20%20Test%3A%20%7Blen(y_test)%7D%22)%0A%20%20%20%20y.tail()%0A%20%20%20%20return%20forecasting_horizon%2C%20y_test%2C%20y_train%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.%20Configure%20Calibration%20Size%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%20calibration_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D12%2C%0A%20%20%20%20%20%20%20%20stop%3D60%2C%0A%20%20%20%20%20%20%20%20step%3D6%2C%0A%20%20%20%20%20%20%20%20value%3D24%2C%0A%20%20%20%20%20%20%20%20label%3D%22calibration_size%20(months%20held%20out%20from%20training%20for%20calibration)%22%2C%0A%20%20%20%20)%0A%20%20%20%20calibration_slider%0A%20%20%20%20return%20(calibration_slider%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20FeaturePipeline%2C%0A%20%20%20%20LagTransformer%2C%0A%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20Ridge%2C%0A%20%20%20%20SeasonalDifferencing%2C%0A%20%20%20%20SplitConformalForecaster%2C%0A%20%20%20%20calibration_slider%2C%0A%20%20%20%20forecasting_horizon%2C%0A%20%20%20%20y_train%2C%0A)%3A%0A%20%20%20%20calibration_size%20%3D%20calibration_slider.value%0A%20%20%20%20point_forecaster%20%3D%20PointReductionForecaster(%0A%20%20%20%20%20%20%20%20estimator%3DRidge()%2C%0A%20%20%20%20%20%20%20%20target_transformer%3DSeasonalDifferencing(seasonality%3D12)%2C%0A%20%20%20%20%20%20%20%20feature_transformer%3DFeaturePipeline(%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22lags%22%2C%20LagTransformer(lag%3D%5B1%2C%202%2C%203%2C%2012%5D))%2C%0A%20%20%20%20%20%20%20%20%5D)%2C%0A%20%20%20%20)%0A%20%20%20%20conformal%20%3D%20SplitConformalForecaster(%0A%20%20%20%20%20%20%20%20point_forecaster%3Dpoint_forecaster%2C%0A%20%20%20%20%20%20%20%20calibration_size%3Dcalibration_size%2C%0A%20%20%20%20)%0A%20%20%20%20conformal.fit(y_train%2C%20forecasting_horizon%3Dforecasting_horizon)%0A%20%20%20%20print(f%22Fitted%20conformal%20forecaster%20(calibration_size%3D%7Bcalibration_size%7D)%22)%0A%20%20%20%20return%20(conformal%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.%20Predict%20Intervals%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(conformal%2C%20forecasting_horizon)%3A%0A%20%20%20%20y_pred_int%20%3D%20conformal.predict_interval(forecasting_horizon%3Dforecasting_horizon)%0A%20%20%20%20print(%22Interval%20columns%3A%22%2C%20y_pred_int.columns)%0A%20%20%20%20y_pred_int%0A%20%20%20%20return%20(y_pred_int%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%204.%20Visualize%20and%20Check%20Coverage%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(EmpiricalCoverage%2C%20plot_forecast%2C%20y_pred_int%2C%20y_test%2C%20y_train)%3A%0A%20%20%20%20fig%20%3D%20plot_forecast(y_test%2C%20y_pred_int%2C%20y_train%3Dy_train%5B-24%3A%5D)%0A%20%20%20%20cov_scorer%20%3D%20EmpiricalCoverage()%0A%20%20%20%20cov_scorer.fit(y_train)%0A%20%20%20%20empirical_cov%20%3D%20cov_scorer.score(y_test%2C%20y_pred_int)%0A%20%20%20%20print(f%22Target%20coverage%3A%20%20%20%200.95%22)%0A%20%20%20%20print(f%22Empirical%20coverage%3A%20%7Bempirical_cov%3A.3f%7D%22)%0A%20%20%20%20fig%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%5BInterval%20Forecasting%5D(%2Fpages%2Ftutorials%2Finterval-forecasting%2F)%20for%20the%20full%20guide%0A%20%20%20%20-%20%5BInterval%20Forecasting%20How-To%5D(%2Fpages%2Fhow-to%2Finterval-forecasting%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
6732e3ae2bd2eeb05a4a11c13b7c8177