Skip to content

Commit 5c988ec

Browse files
committed
Update tutorial
1 parent d18a814 commit 5c988ec

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

doc/user-guide/climada_util_calibrate.ipynb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
],
9797
"source": [
9898
"import pandas as pd\n",
99-
"from sklearn.metrics import mean_squared_log_error\n",
10099
"\n",
101100
"from climada.util import log_level\n",
102101
"from climada.util.api_client import Client\n",
@@ -106,6 +105,7 @@
106105
" BayesianOptimizer,\n",
107106
" BayesianOptimizerController,\n",
108107
" OutputEvaluator,\n",
108+
" msle,\n",
109109
")\n",
110110
"\n",
111111
"# Load hazard and exposure from Data API\n",
@@ -133,7 +133,7 @@
133133
" # Estimated parameter bounds\n",
134134
" bounds={\"v_half\": (26, 100)},\n",
135135
" # Cost function\n",
136-
" cost_func=mean_squared_log_error,\n",
136+
" cost_func=msle,\n",
137137
" # Transform impact to pandas Dataframe with same structure as data\n",
138138
" impact_to_dataframe=lambda impact: impact.impact_at_reg(exposure.gdf[\"region_id\"]),\n",
139139
")\n",
@@ -2192,7 +2192,7 @@
21922192
},
21932193
{
21942194
"cell_type": "code",
2195-
"execution_count": 20,
2195+
"execution_count": null,
21962196
"metadata": {},
21972197
"outputs": [
21982198
{
@@ -2211,8 +2211,12 @@
22112211
}
22122212
],
22132213
"source": [
2214-
"from climada.util.calibrate import Input, BayesianOptimizer, BayesianOptimizerController\n",
2215-
"from sklearn.metrics import mean_squared_log_error\n",
2214+
"from climada.util.calibrate import (\n",
2215+
" Input,\n",
2216+
" BayesianOptimizer,\n",
2217+
" BayesianOptimizerController,\n",
2218+
" msle,\n",
2219+
")\n",
22162220
"\n",
22172221
"from climada.util import log_level\n",
22182222
"\n",
@@ -2223,7 +2227,7 @@
22232227
" exposure=exposure,\n",
22242228
" data=data,\n",
22252229
" impact_func_creator=impact_func_tc,\n",
2226-
" cost_func=lambda x, y, w: mean_squared_log_error(x, y, sample_weight=w),\n",
2230+
" cost_func=msle,\n",
22272231
" impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n",
22282232
" bounds=bounds,\n",
22292233
" )\n",
@@ -3726,9 +3730,8 @@
37263730
" Input,\n",
37273731
" BayesianOptimizer,\n",
37283732
" OutputEvaluator,\n",
3729-
" BayesianOptimizerOutputEvaluator,\n",
3733+
" msle,\n",
37303734
")\n",
3731-
"from sklearn.metrics import mean_squared_log_error\n",
37323735
"import matplotlib.pyplot as plt\n",
37333736
"\n",
37343737
"\n",
@@ -3740,7 +3743,7 @@
37403743
" exposure=exposure,\n",
37413744
" data=data,\n",
37423745
" impact_func_creator=impact_func_tc,\n",
3743-
" cost_func=mean_squared_log_error,\n",
3746+
" cost_func=msle,\n",
37443747
" impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n",
37453748
" bounds=bounds,\n",
37463749
" **input_kwargs,\n",
@@ -3988,7 +3991,7 @@
39883991
},
39893992
{
39903993
"cell_type": "code",
3991-
"execution_count": 35,
3994+
"execution_count": null,
39923995
"metadata": {},
39933996
"outputs": [
39943997
{
@@ -4110,21 +4113,18 @@
41104113
" AverageEnsembleOptimizer,\n",
41114114
" BayesianOptimizer,\n",
41124115
" BayesianOptimizerController,\n",
4116+
" msle,\n",
41134117
")\n",
41144118
"from climada.util import log_level\n",
41154119
"\n",
4116-
"from sklearn.metrics import mean_squared_log_error\n",
4117-
"\n",
41184120
"# Define calibration input\n",
41194121
"with log_level(\"WARNING\", name_prefix=\"climada.util.calibrate\"):\n",
41204122
" input = Input(\n",
41214123
" hazard=hazard,\n",
41224124
" exposure=exposure,\n",
41234125
" data=data,\n",
41244126
" impact_func_creator=impact_func_tc,\n",
4125-
" cost_func=lambda data, predicted, weights: mean_squared_log_error(\n",
4126-
" data, predicted, sample_weight=weights\n",
4127-
" ),\n",
4127+
" cost_func=msle,\n",
41284128
" impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n",
41294129
" bounds=bounds,\n",
41304130
" )\n",
@@ -4475,7 +4475,7 @@
44754475
},
44764476
{
44774477
"cell_type": "code",
4478-
"execution_count": 34,
4478+
"execution_count": null,
44794479
"metadata": {},
44804480
"outputs": [
44814481
{
@@ -4668,7 +4668,7 @@
46684668
" exposure=exposure,\n",
46694669
" data=data,\n",
46704670
" impact_func_creator=impact_func_tc,\n",
4671-
" cost_func=lambda x, y, w: mean_squared_log_error(x, y, sample_weight=w),\n",
4671+
" cost_func=msle,\n",
46724672
" impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n",
46734673
" bounds=bounds,\n",
46744674
" )\n",

0 commit comments

Comments
 (0)