%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%22optuna%22%2C%0A%23%20%20%20%20%20%22polars%22%2C%0A%23%20%20%20%20%20%22scikit-learn%22%2C%0A%23%20%20%20%20%20%22yohou%22%2C%0A%23%20%20%20%20%20%22yohou-optuna%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.23.5%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%20How%20to%20Visualize%20Search%20Results%0A%0A%20%20%20%20Access%20the%20Optuna%20%60study_%60%20object%20from%20a%20fitted%20%60OptunaSearchCV%60%20and%20produce%20optimization%20history%2C%20parameter%20importance%2C%20contour%2C%20and%20slice%20plots%20alongside%20yohou's%20forecast%20diagnostics.%0A%0A%20%20%20%20**Prerequisites**%3A%20familiarity%20with%20%5B%60OptunaSearchCV%60%5D(%2Fpages%2Fapi%2Fgenerated%2Fyohou_optuna.search.OptunaSearchCV%2F)%20(see%20%5BOptunaSearchCV%20Quickstart%5D(%2Fexamples%2Foptuna_search%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%20import%20optuna%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20from%20optuna.distributions%20import%20CategoricalDistribution%2C%20FloatDistribution%0A%20%20%20%20from%20sklearn.linear_model%20import%20Ridge%0A%0A%20%20%20%20from%20yohou.datasets%20import%20fetch_electricity_demand%0A%20%20%20%20from%20yohou.metrics%20import%20MeanAbsoluteError%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_residuals%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%0A%20%20%20%20from%20yohou_optuna%20import%20OptunaSearchCV%2C%20Sampler%0A%0A%20%20%20%20optuna.logging.set_verbosity(optuna.logging.WARNING)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20CategoricalDistribution%2C%0A%20%20%20%20%20%20%20%20FloatDistribution%2C%0A%20%20%20%20%20%20%20%20MeanAbsoluteError%2C%0A%20%20%20%20%20%20%20%20OptunaSearchCV%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%20Sampler%2C%0A%20%20%20%20%20%20%20%20fetch_electricity_demand%2C%0A%20%20%20%20%20%20%20%20optuna%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_residuals%2C%0A%20%20%20%20%20%20%20%20plot_time_series%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%20the%20Data%0A%0A%20%20%20%20The%20Australian%20Electricity%20Demand%20dataset%20contains%2030-minute%20measurements%0A%20%20%20%20of%20electricity%20demand%20across%20multiple%20states.%20We%20use%20a%20subset%20of%20Victoria's%0A%20%20%20%20demand%20column%20to%20keep%20the%20search%20fast.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(fetch_electricity_demand)%3A%0A%20%20%20%20y_full%20%3D%20fetch_electricity_demand().frame%0A%20%20%20%20y_all%20%3D%20y_full.select(%5B%22time%22%2C%20%22vic__demand%22%5D).rename(%7B%22vic__demand%22%3A%20%22demand%22%7D).head(500)%0A%20%20%20%20plot_time_series_fig%20%3D%20None%0A%20%20%20%20return%20(y_all%2C)%0A%0A%0A%40app.cell%0Adef%20_(plot_time_series%2C%20y_all)%3A%0A%20%20%20%20plot_time_series(y_all%2C%20title%3D%22Victoria%20Electricity%20Demand%20(Subset)%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(y_all)%3A%0A%20%20%20%20y_train%20%3D%20y_all.head(400)%0A%20%20%20%20y_test%20%3D%20y_all.tail(24)%0A%20%20%20%20return%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.%20Run%20the%20Search%0A%0A%20%20%20%20Search%20over%20two%20parameters%20with%2025%20trials%20to%20generate%20data%20for%20the%20plots.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20CategoricalDistribution%2C%0A%20%20%20%20FloatDistribution%2C%0A%20%20%20%20MeanAbsoluteError%2C%0A%20%20%20%20OptunaSearchCV%2C%0A%20%20%20%20PointReductionForecaster%2C%0A%20%20%20%20Ridge%2C%0A%20%20%20%20Sampler%2C%0A%20%20%20%20optuna%2C%0A%20%20%20%20y_train%2C%0A)%3A%0A%20%20%20%20search%20%3D%20OptunaSearchCV(%0A%20%20%20%20%20%20%20%20forecaster%3DPointReductionForecaster(estimator%3DRidge())%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%20FloatDistribution(0.001%2C%20100.0%2C%20log%3DTrue)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22estimator__fit_intercept%22%3A%20CategoricalDistribution(%5BTrue%2C%20False%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%20sampler%3DSampler(sampler%3Doptuna.samplers.TPESampler%2C%20seed%3D42)%2C%0A%20%20%20%20%20%20%20%20n_trials%3D25%2C%0A%20%20%20%20%20%20%20%20cv%3D3%2C%0A%20%20%20%20%20%20%20%20refit%3DTrue%2C%0A%20%20%20%20%20%20%20%20verbose%3D0%2C%0A%20%20%20%20)%0A%0A%20%20%20%20search.fit(y_train%2C%20forecasting_horizon%3D24)%0A%20%20%20%20return%20(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.%20Optuna%20Study%20Visualizations%0A%0A%20%20%20%20Access%20the%20underlying%20Optuna%20study%20via%20%60search.study_%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**Optimization%20History**%3A%20objective%20value%20across%20trials%20with%20a%20running%20best%20line.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(optuna%2C%20search)%3A%0A%20%20%20%20optuna.visualization.plot_optimization_history(search.study_)%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**Parameter%20Importances**%3A%20contribution%20of%20each%20hyperparameter%20to%20objective%20variation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(optuna%2C%20search)%3A%0A%20%20%20%20optuna.visualization.plot_param_importances(search.study_)%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**Slice%20Plots**%3A%20per-parameter%20objective%20values%20across%20trials.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(optuna%2C%20search)%3A%0A%20%20%20%20optuna.visualization.plot_slice(search.study_)%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**Contour%20Plot**%3A%20joint%20parameter%20interaction%20as%20a%202D%20surface.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(optuna%2C%20search)%3A%0A%20%20%20%20optuna.visualization.plot_contour(%0A%20%20%20%20%20%20%20%20search.study_%2C%0A%20%20%20%20%20%20%20%20params%3D%5B%22estimator__alpha%22%2C%20%22estimator__fit_intercept%22%5D%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.%20Yohou%20Forecast%20Diagnostics%0A%0A%20%20%20%20Use%20yohou's%20plotting%20module%20for%20forecast-level%20analysis.%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%20search)%3A%0A%20%20%20%20plot_cv_results_scatter(%0A%20%20%20%20%20%20%20%20search.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%20higher_is_better%3DFalse%2C%0A%20%20%20%20%20%20%20%20title%3D%22CV%20Score%20vs%20Regularization%20Strength%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(search)%3A%0A%20%20%20%20y_pred%20%3D%20search.predict(forecasting_horizon%3D24)%0A%20%20%20%20y_pred%0A%20%20%20%20return%20(y_pred%2C)%0A%0A%0A%40app.cell%0Adef%20_(plot_forecast%2C%20y_pred%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%2C%0A%20%20%20%20%20%20%20%20y_train%3Dy_train%2C%0A%20%20%20%20%20%20%20%20n_history%3D48%2C%0A%20%20%20%20%20%20%20%20title%3D%22Best%20Forecaster%3A%20Predicted%20vs%20Actual%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plot_residuals%2C%20y_pred%2C%20y_test)%3A%0A%20%20%20%20plot_residuals(%0A%20%20%20%20%20%20%20%20y_pred%2C%0A%20%20%20%20%20%20%20%20y_test%2C%0A%20%20%20%20%20%20%20%20title%3D%22Forecast%20Residuals%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%20Key%20Takeaways%0A%0A%20%20%20%20-%20**%60search.study_%60**%20exposes%20the%20full%20Optuna%20study%20for%20native%20visualization%0A%20%20%20%20-%20**%60plot_optimization_history%60**%20reveals%20sampler%20convergence%20across%20trials%0A%20%20%20%20-%20**%60plot_param_importances%60**%20identifies%20which%20hyperparameters%20matter%20most%0A%20%20%20%20-%20**%60plot_slice%60%20and%20%60plot_contour%60**%20show%20individual%20and%20joint%20parameter%20effects%0A%20%20%20%20-%20**%60plot_cv_results_scatter%60**%20from%20yohou%20visualizes%20score%20vs%20parameter%20values%0A%20%20%20%20-%20**%60plot_forecast%60%20and%20%60plot_residuals%60**%20provide%20forecast-level%20diagnostics%0A%0A%20%20%20%20%23%23%20Next%20Steps%0A%0A%20%20%20%20-%20%5BHow%20to%20Run%20a%20Multi-Metric%20Search%5D(%2Fexamples%2Fmulti_metric_search%2F)%3A%20track%20multiple%20metrics%20and%20compare%20rankings%0A%20%20%20%20-%20%5BHow%20to%20Tune%20on%20Panel%20Data%5D(%2Fexamples%2Fpanel_tuning%2F)%3A%20grouped%20time%20series%20optimization%0A%20%20%20%20-%20%5BOptunaSearchCV%20Quickstart%5D(%2Fexamples%2Foptuna_search%2F)%3A%20minimal%20end-to-end%20walkthrough%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
28b2476c4d53aeb54c71a67e0f6bc91f