Skip to content

Commit

Permalink
Small fix to notebooks (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrit110 authored Nov 24, 2023
1 parent b916535 commit b4a94c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 69 deletions.
48 changes: 5 additions & 43 deletions docs/source/tutorials/mimiciv/mortality_prediction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1228,49 +1228,11 @@
"shutil.copy(f\"{report_path}\", \".\")\n",
"for i in range(4):\n",
" report._model_card.overview = None\n",
" report._model_card.quantitative_analysis = None\n",
" results_flat = flatten_results_dict(\n",
" results=results,\n",
" remove_metrics=[\"BinaryROCCurve\", \"BinaryPrecisionRecallCurve\"],\n",
" model_name=model_name,\n",
" )\n",
"\n",
" for name, metric in results_flat.items():\n",
" split, name = name.split(\"/\") # noqa: PLW2901\n",
" descriptions = {\n",
" \"BinaryPrecision\": \"The proportion of predicted positive instances that are correctly predicted.\",\n",
" \"BinaryRecall\": \"The proportion of actual positive instances that are correctly predicted. Also known as recall or true positive rate.\",\n",
" \"BinaryAccuracy\": \"The proportion of all instances that are correctly predicted.\",\n",
" \"BinaryAUROC\": \"The area under the receiver operating characteristic curve (AUROC) is a measure of the performance of a binary classification model.\",\n",
" \"BinaryF1Score\": \"The harmonic mean of precision and recall.\",\n",
" }\n",
" report.log_quantitative_analysis(\n",
" \"performance\",\n",
" name=name,\n",
" value=np.clip(metric + np.random.normal(0, 0.1), 0, 1),\n",
" description=descriptions[name],\n",
" metric_slice=split,\n",
" pass_fail_thresholds=0.7,\n",
" pass_fail_threshold_fns=lambda x, threshold: bool(x >= threshold),\n",
" )\n",
"\n",
" for name, metric in results_flat.items():\n",
" split, name = name.split(\"/\") # noqa: PLW2901\n",
" descriptions = {\n",
" \"BinaryPrecision\": \"The proportion of predicted positive instances that are correctly predicted.\",\n",
" \"BinaryRecall\": \"The proportion of actual positive instances that are correctly predicted. Also known as recall or true positive rate.\",\n",
" \"BinaryAccuracy\": \"The proportion of all instances that are correctly predicted.\",\n",
" \"BinaryAUROC\": \"The area under the receiver operating characteristic curve (AUROC) is a measure of the performance of a binary classification model.\",\n",
" \"BinaryF1Score\": \"The harmonic mean of precision and recall.\",\n",
" }\n",
" report.log_quantitative_analysis(\n",
" \"performance\",\n",
" name=name,\n",
" value=np.clip(metric + np.random.normal(0, 0.1), 0, 1),\n",
" description=descriptions[name],\n",
" metric_slice=split,\n",
" pass_fail_thresholds=0.7,\n",
" pass_fail_threshold_fns=lambda x, threshold: bool(x >= threshold),\n",
" for metric in report._model_card.quantitative_analysis.performance_metrics:\n",
" metric.value = np.clip(\n",
" metric.value + np.random.normal(0, 0.1),\n",
" 0,\n",
" 1,\n",
" )\n",
" report_path = report.export(\n",
" output_filename=\"mortality_report_periodic.html\",\n",
Expand Down
32 changes: 6 additions & 26 deletions docs/source/tutorials/synthea/los_prediction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@
"report.log_plotly_figure(\n",
" fig=conf_plot,\n",
" caption=\"Confusion Matrix\",\n",
" section_name=\"fairness analysis\",\n",
" section_name=\"quantitative analysis\",\n",
")\n",
"conf_plot.show()"
]
Expand Down Expand Up @@ -1460,31 +1460,11 @@
"shutil.copy(f\"{report_path}\", \".\")\n",
"for i in range(4):\n",
" report._model_card.overview = None\n",
" report._model_card.quantitative_analysis = None\n",
" results_flat = flatten_results_dict(\n",
" results=results,\n",
" remove_metrics=[\"BinaryROCCurve\", \"BinaryPrecisionRecallCurve\"],\n",
" model_name=model_name,\n",
" )\n",
" for name, metric in results_flat.items():\n",
" split, name = name.split(\"/\") # noqa: PLW2901\n",
" if name == \"BinaryStatScores\":\n",
" continue\n",
" descriptions = {\n",
" \"BinaryPrecision\": \"The proportion of predicted positive instances that are correctly predicted.\",\n",
" \"BinaryRecall\": \"The proportion of actual positive instances that are correctly predicted. Also known as recall or true positive rate.\",\n",
" \"BinaryAccuracy\": \"The proportion of all instances that are correctly predicted.\",\n",
" \"BinaryAUROC\": \"The area under the receiver operating characteristic curve (AUROC) is a measure of the performance of a binary classification model.\",\n",
" \"BinaryF1Score\": \"The harmonic mean of precision and recall.\",\n",
" }\n",
" report.log_quantitative_analysis(\n",
" \"performance\",\n",
" name=name,\n",
" value=np.clip(metric + np.random.normal(0, 0.1), 0, 1),\n",
" description=descriptions[name],\n",
" metric_slice=split,\n",
" pass_fail_thresholds=0.7,\n",
" pass_fail_threshold_fns=lambda x, threshold: bool(x >= threshold),\n",
" for metric in report._model_card.quantitative_analysis.performance_metrics:\n",
" metric.value = np.clip(\n",
" metric.value + np.random.normal(0, 0.1),\n",
" 0,\n",
" 1,\n",
" )\n",
" report_path = report.export(\n",
" output_filename=\"length_of_stay_report_periodic.html\",\n",
Expand Down

0 comments on commit b4a94c6

Please sign in to comment.