diff --git a/Notebooks/eval_precipitation_sensitivity.ipynb b/Notebooks/eval_precipitation_sensitivity.ipynb index 7da323545988cff8524cf1e5ed943bb5efcea0e5..eb55dd81cbd8018807b939e5e1214a69a230c94e 100644 --- a/Notebooks/eval_precipitation_sensitivity.ipynb +++ b/Notebooks/eval_precipitation_sensitivity.ipynb @@ -334,13 +334,37 @@ " print('({:.1f} mm), RMSE of P{:.0f} = {:.2f} mm'.format(k, quantile * 100, rmse_ex.mean().to_array().item()))" ] }, + { + "cell_type": "markdown", + "id": "f6dfd17e-6eb4-465f-a624-bd5c8f79c99b", + "metadata": {}, + "source": [ + "### ROC: Receiver operating characteristics" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "26b130a6-5caa-490f-93ce-72f4a5f53412", + "id": "92733418-8840-46c2-bf33-adf93b78c646", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# true and predicted probability of precipitation\n", + "for k, v in y_pred.items():\n", + " p_true = (y_true.precipitation > k).values.flatten()\n", + " p_pred = v.prob.values.flatten()\n", + " \n", + " # apply mask of valid pixels\n", + " mask = (~np.isnan(p_true) & ~np.isnan(p_pred))\n", + " p_pred = p_pred[mask]\n", + " p_true = p_true[mask].astype(float)\n", + " \n", + " # calculate ROC: false positive rate vs. true positive rate\n", + " fpr, tpr, _ = roc_curve(p_true, p_pred)\n", + " area = auc(fpr, tpr) # area under ROC curve\n", + " rocss = 2 * area - 1 # ROC skill score (cf. https://journals.ametsoc.org/view/journals/clim/16/24/1520-0442_2003_016_4145_otrsop_2.0.co_2.xml)\n", + " print('({:.1f} mm), ROCSS = {:.2f}'.format(k, rocss))" + ] } ], "metadata": {