|
96 | 96 | ], |
97 | 97 | "source": [ |
98 | 98 | "import pandas as pd\n", |
99 | | - "from sklearn.metrics import mean_squared_log_error\n", |
100 | 99 | "\n", |
101 | 100 | "from climada.util import log_level\n", |
102 | 101 | "from climada.util.api_client import Client\n", |
|
106 | 105 | " BayesianOptimizer,\n", |
107 | 106 | " BayesianOptimizerController,\n", |
108 | 107 | " OutputEvaluator,\n", |
| 108 | + " msle,\n", |
109 | 109 | ")\n", |
110 | 110 | "\n", |
111 | 111 | "# Load hazard and exposure from Data API\n", |
|
133 | 133 | " # Estimated parameter bounds\n", |
134 | 134 | " bounds={\"v_half\": (26, 100)},\n", |
135 | 135 | " # Cost function\n", |
136 | | - " cost_func=mean_squared_log_error,\n", |
| 136 | + " cost_func=msle,\n", |
137 | 137 | " # Transform impact to pandas Dataframe with same structure as data\n", |
138 | 138 | " impact_to_dataframe=lambda impact: impact.impact_at_reg(exposure.gdf[\"region_id\"]),\n", |
139 | 139 | ")\n", |
|
2192 | 2192 | }, |
2193 | 2193 | { |
2194 | 2194 | "cell_type": "code", |
2195 | | - "execution_count": 20, |
| 2195 | + "execution_count": null, |
2196 | 2196 | "metadata": {}, |
2197 | 2197 | "outputs": [ |
2198 | 2198 | { |
|
2211 | 2211 | } |
2212 | 2212 | ], |
2213 | 2213 | "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", |
2216 | 2220 | "\n", |
2217 | 2221 | "from climada.util import log_level\n", |
2218 | 2222 | "\n", |
|
2223 | 2227 | " exposure=exposure,\n", |
2224 | 2228 | " data=data,\n", |
2225 | 2229 | " 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", |
2227 | 2231 | " impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n", |
2228 | 2232 | " bounds=bounds,\n", |
2229 | 2233 | " )\n", |
|
3726 | 3730 | " Input,\n", |
3727 | 3731 | " BayesianOptimizer,\n", |
3728 | 3732 | " OutputEvaluator,\n", |
3729 | | - " BayesianOptimizerOutputEvaluator,\n", |
| 3733 | + " msle,\n", |
3730 | 3734 | ")\n", |
3731 | | - "from sklearn.metrics import mean_squared_log_error\n", |
3732 | 3735 | "import matplotlib.pyplot as plt\n", |
3733 | 3736 | "\n", |
3734 | 3737 | "\n", |
|
3740 | 3743 | " exposure=exposure,\n", |
3741 | 3744 | " data=data,\n", |
3742 | 3745 | " impact_func_creator=impact_func_tc,\n", |
3743 | | - " cost_func=mean_squared_log_error,\n", |
| 3746 | + " cost_func=msle,\n", |
3744 | 3747 | " impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n", |
3745 | 3748 | " bounds=bounds,\n", |
3746 | 3749 | " **input_kwargs,\n", |
|
3988 | 3991 | }, |
3989 | 3992 | { |
3990 | 3993 | "cell_type": "code", |
3991 | | - "execution_count": 35, |
| 3994 | + "execution_count": null, |
3992 | 3995 | "metadata": {}, |
3993 | 3996 | "outputs": [ |
3994 | 3997 | { |
|
4110 | 4113 | " AverageEnsembleOptimizer,\n", |
4111 | 4114 | " BayesianOptimizer,\n", |
4112 | 4115 | " BayesianOptimizerController,\n", |
| 4116 | + " msle,\n", |
4113 | 4117 | ")\n", |
4114 | 4118 | "from climada.util import log_level\n", |
4115 | 4119 | "\n", |
4116 | | - "from sklearn.metrics import mean_squared_log_error\n", |
4117 | | - "\n", |
4118 | 4120 | "# Define calibration input\n", |
4119 | 4121 | "with log_level(\"WARNING\", name_prefix=\"climada.util.calibrate\"):\n", |
4120 | 4122 | " input = Input(\n", |
4121 | 4123 | " hazard=hazard,\n", |
4122 | 4124 | " exposure=exposure,\n", |
4123 | 4125 | " data=data,\n", |
4124 | 4126 | " 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", |
4128 | 4128 | " impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n", |
4129 | 4129 | " bounds=bounds,\n", |
4130 | 4130 | " )\n", |
|
4475 | 4475 | }, |
4476 | 4476 | { |
4477 | 4477 | "cell_type": "code", |
4478 | | - "execution_count": 34, |
| 4478 | + "execution_count": null, |
4479 | 4479 | "metadata": {}, |
4480 | 4480 | "outputs": [ |
4481 | 4481 | { |
|
4668 | 4668 | " exposure=exposure,\n", |
4669 | 4669 | " data=data,\n", |
4670 | 4670 | " 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", |
4672 | 4672 | " impact_to_dataframe=lambda imp: imp.impact_at_reg(exposure.gdf[\"region_id\"]),\n", |
4673 | 4673 | " bounds=bounds,\n", |
4674 | 4674 | " )\n", |
|
0 commit comments