Skip to content

Commit 252e7f6

Browse files
committed
Add eval utils and extra evaluation plots
1 parent 48e26a8 commit 252e7f6

File tree

2 files changed

+247
-51
lines changed

2 files changed

+247
-51
lines changed

EvaluateModel.ipynb

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,6 @@
311311
"p_values"
312312
]
313313
},
314-
{
315-
"cell_type": "markdown",
316-
"metadata": {},
317-
"source": [
318-
"Difference boxplots"
319-
]
320-
},
321-
{
322-
"cell_type": "code",
323-
"execution_count": null,
324-
"metadata": {},
325-
"outputs": [],
326-
"source": [
327-
"plot_difference_boxplots(results_df)"
328-
]
329-
},
330314
{
331315
"cell_type": "code",
332316
"execution_count": null,
@@ -368,6 +352,9 @@
368352
" ax.set_xlabel(\"Age Band\")\n",
369353
" ax.set_ylabel(f\"Cohen's kappa score\")\n",
370354
" plt.title(f\"Performance by {x}\")\n",
355+
" \n",
356+
" handles, _ = ax.get_legend_handles_labels()\n",
357+
" ax.legend(handles, [\"Baseline\", \"ActiNet\"], title=hue)\n",
371358
" plt.show()"
372359
]
373360
},
@@ -433,8 +420,8 @@
433420
" \n",
434421
" y_true_bbaa, y_pred_bbaa, y_true_actinet, y_pred_actinet, _ = build_confusion_matrix_data(results_df)\n",
435422
" \n",
436-
" plot_confusion_matrix(y_true_bbaa, y_pred_bbaa, 'accelerometer', ax=axs[0], fontsize=fontsize*0.8)\n",
437-
" plot_confusion_matrix(y_true_actinet, y_pred_actinet, 'actinet', ax=axs[1], fontsize=fontsize*0.8)\n",
423+
" plot_confusion_matrix(y_true_bbaa, y_pred_bbaa, 'Baseline', ax=axs[0], fontsize=fontsize*0.8)\n",
424+
" plot_confusion_matrix(y_true_actinet, y_pred_actinet, 'ActiNet', ax=axs[1], fontsize=fontsize*0.8)\n",
438425
" fig.tight_layout()\n",
439426
" plot_and_save_fig(fig, save_path)\n",
440427
" \n",
@@ -453,9 +440,9 @@
453440
" subfig.suptitle(f\"{group_by}: {group} (n = {population})\", fontsize=fontsize*0.9)\n",
454441
" axs = subfig.subplots(nrows=1, ncols=2, sharey=True)\n",
455442
"\n",
456-
" plot_confusion_matrix(y_true_bbaa, y_pred_bbaa, 'accelerometer', ax=axs[0], fontsize=fontsize*0.8)\n",
457-
" plot_confusion_matrix(y_true_actinet, y_pred_actinet, 'actinet', ax=axs[1], fontsize=fontsize*0.8)\n",
458-
" \n",
443+
" plot_confusion_matrix(y_true_bbaa, y_pred_bbaa, 'Baseline', ax=axs[0], fontsize=fontsize*0.8)\n",
444+
" plot_confusion_matrix(y_true_actinet, y_pred_actinet, 'ActiNet', ax=axs[1], fontsize=fontsize*0.8)\n",
445+
"\n",
459446
" plot_and_save_fig(fig, save_path)"
460447
]
461448
},
@@ -465,9 +452,9 @@
465452
"metadata": {},
466453
"outputs": [],
467454
"source": [
468-
"generate_confusion_matrices(results_df, save_path=out_dir+\"/plots/conf_full_population.pdf\", fontsize=18)\n",
469-
"generate_confusion_matrices(results_df, group_by=\"Sex\", save_path=out_dir+\"/plots/conf_by_sex.pdf\", fontsize=18)\n",
470-
"generate_confusion_matrices(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/conf_by_age.pdf\", fontsize=18)"
455+
"generate_confusion_matrices(results_df, save_path=out_dir+\"/plots/conf_full_population.png\", fontsize=18)\n",
456+
"generate_confusion_matrices(results_df, group_by=\"Sex\", save_path=out_dir+\"/plots/conf_by_sex.png\", fontsize=18)\n",
457+
"generate_confusion_matrices(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/conf_by_age.png\", fontsize=18)"
471458
]
472459
},
473460
{
@@ -483,12 +470,76 @@
483470
"metadata": {},
484471
"outputs": [],
485472
"source": [
486-
"generate_bland_altman_plots(results_df, save_path=out_dir+\"/plots/ba_full_population.pdf\")\n",
473+
"generate_bland_altman_plots(results_df, save_path=out_dir+\"/plots/ba_full_population.png\")\n",
487474
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Female\"], subset=\"female\",\n",
488-
" save_path=out_dir+\"/plots/ba_by_sex_female.pdf\")\n",
475+
" save_path=out_dir+\"/plots/ba_by_sex_female.png\")\n",
489476
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Male\"], subset=\"male\",\n",
490-
" save_path=out_dir+\"/plots/ba_by_sex_male.pdf\")\n",
491-
"generate_bland_altman_plots(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/ba_by_age.pdf\")"
477+
" save_path=out_dir+\"/plots/ba_by_sex_male.png\")\n",
478+
"generate_bland_altman_plots(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/ba_by_age.png\")"
479+
]
480+
},
481+
{
482+
"cell_type": "code",
483+
"execution_count": null,
484+
"metadata": {},
485+
"outputs": [],
486+
"source": [
487+
"generate_bland_altman_plots(results_df, save_path=out_dir+\"/plots/ba__true_actinet_full_population.png\", compare_to_true='actinet')\n",
488+
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Female\"], subset=\"female\",\n",
489+
" save_path=out_dir+\"/plots/ba__true_actinet_by_sex_female.png\", compare_to_true='actinet')\n",
490+
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Male\"], subset=\"male\",\n",
491+
" save_path=out_dir+\"/plots/ba__true_actinet_by_sex_male.png\", compare_to_true='actinet')\n",
492+
"generate_bland_altman_plots(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/ba__true_actinet_by_age.png\", compare_to_true='actinet')"
493+
]
494+
},
495+
{
496+
"cell_type": "code",
497+
"execution_count": null,
498+
"metadata": {},
499+
"outputs": [],
500+
"source": [
501+
"generate_bland_altman_plots(results_df, save_path=out_dir+\"/plots/ba_true_bbaa_full_population.png\", compare_to_true='bbaa')\n",
502+
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Female\"], subset=\"female\",\n",
503+
" save_path=out_dir+\"/plots/ba_true_bbaa_by_sex_female.png\", compare_to_true='bbaa')\n",
504+
"generate_bland_altman_plots(results_df[results_df[\"Sex\"]==\"Male\"], subset=\"male\",\n",
505+
" save_path=out_dir+\"/plots/ba_true_bbaa_by_sex_male.png\", compare_to_true='bbaa')\n",
506+
"generate_bland_altman_plots(results_df, group_by=\"Age Band\", save_path=out_dir+\"/plots/ba_true_bbaa_by_age.png\", compare_to_true='bbaa')"
507+
]
508+
},
509+
{
510+
"cell_type": "code",
511+
"execution_count": null,
512+
"metadata": {},
513+
"outputs": [],
514+
"source": [
515+
"build_mae_table(results_df)"
516+
]
517+
},
518+
{
519+
"cell_type": "code",
520+
"execution_count": null,
521+
"metadata": {},
522+
"outputs": [],
523+
"source": [
524+
"plot_errors(results_df, save_path = out_dir + \"/plots/errors_full_population.png\")"
525+
]
526+
},
527+
{
528+
"cell_type": "code",
529+
"execution_count": null,
530+
"metadata": {},
531+
"outputs": [],
532+
"source": [
533+
"plot_errors(results_df, group_by='Age Band', save_path = out_dir + \"/plots/errors_by_age.png\")"
534+
]
535+
},
536+
{
537+
"cell_type": "code",
538+
"execution_count": null,
539+
"metadata": {},
540+
"outputs": [],
541+
"source": [
542+
"plot_errors(results_df, group_by='Sex', save_path=out_dir + \"/plots/errors_by_sex.png\")"
492543
]
493544
}
494545
],

0 commit comments

Comments
 (0)