ROCcurve.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import pandas as pd
  2. import seaborn as sns
  3. import matplotlib.pyplot as plt
  4. import os
  5. import numpy as np
  6. # Read data from the CSV file
  7. script_dir = os.path.dirname(__file__)
  8. file_path = os.path.join(script_dir, '..', 'input')
  9. out_path = os.path.join(script_dir, '..', 'figures')
  10. # Load the data
  11. result_df = pd.read_csv(os.path.join(file_path, 'Confusion_matrix_metrics.csv'))
  12. cm = 1/2.54
  13. # Calculate Actual_Label
  14. # Specify the font size for the plot
  15. sns.set_style('ticks')
  16. sns.set(font='Times New Roman', style=None) # Set font to Times New Roman and font size to 9
  17. palette = 'Set1'
  18. subset_df = result_df[(result_df['TP']+result_df['FN'] > 0)]
  19. # Create a Seaborn line plot
  20. g = sns.relplot(
  21. data=subset_df, kind="line",
  22. x="Thresold_ML_Voters", y="Sensitivity-Recall", hue="sequence_name",
  23. dashes=False, markers=True, ci=30,
  24. height=5*cm, aspect=2 # Adjust the aspect to achieve the desired width of 9 cm
  25. )
  26. # Access the individual axes
  27. axes = g.axes.flatten()
  28. axes[0].set_xlabel("AIDAqc Voting Threshold", fontsize=8)
  29. axes[0].set_ylabel("Sensitivity", fontsize=8)
  30. # Loop through each axis and customize spines and tick parameters
  31. for ax in axes:
  32. ax.tick_params(axis='both', which='both', labelsize=8)
  33. ax.spines['top'].set_visible(True)
  34. ax.spines['right'].set_visible(True)
  35. ax.spines['bottom'].set_visible(True)
  36. ax.spines['left'].set_visible(True)
  37. ax.spines['top'].set_linewidth(0.5)
  38. ax.spines['right'].set_linewidth(0.5)
  39. ax.spines['bottom'].set_linewidth(0.5)
  40. ax.spines['left'].set_linewidth(0.5)
  41. g._legend.set_title("")
  42. g._legend.set_fontsize(8)
  43. # Save the figure as SVG and PNG
  44. output_path = out_path
  45. output_filename = "Sensitivity_AIDAqc_Voting_Threshold"
  46. # Save as SVG
  47. g.savefig(f"{output_path}/{output_filename}.svg", format="svg")
  48. # Save as PNG
  49. g.savefig(f"{output_path}/{output_filename}.png", format="png")
  50. plt.show()
  51. #%%
  52. # Create a Seaborn line plot
  53. g = sns.relplot(
  54. data=subset_df, kind="line",
  55. x="Thresold_Human_Voters", y="Sensitivity-Recall", hue="sequence_name",
  56. dashes=False, markers=True, ci=30,
  57. height=5*cm, aspect=2 # Adjust the aspect to achieve the desired width of 9 cm
  58. )
  59. # Access the individual axes
  60. # Access the individual axes
  61. axes = g.axes.flatten()
  62. axes[0].set_xlabel("Manual-rater Voting Threshold", fontsize=8)
  63. axes[0].set_ylabel("Sensitivity", fontsize=8)
  64. # Loop through each axis and customize spines and tick parameters
  65. for ax in axes:
  66. ax.tick_params(axis='both', which='both', labelsize=8)
  67. ax.spines['top'].set_visible(True)
  68. ax.spines['right'].set_visible(True)
  69. ax.spines['bottom'].set_visible(True)
  70. ax.spines['left'].set_visible(True)
  71. ax.spines['top'].set_linewidth(0.5)
  72. ax.spines['right'].set_linewidth(0.5)
  73. ax.spines['bottom'].set_linewidth(0.5)
  74. ax.spines['left'].set_linewidth(0.5)
  75. g._legend.set_title("")
  76. g._legend.set_fontsize(8) # Set legend label size to 8 points
  77. # Save the figure as SVG and PNG
  78. output_path = out_path
  79. output_filename = "Sensitivity_ManualRater_Voting_Threshold"
  80. # Save as SVG
  81. g.savefig(f"{output_path}/{output_filename}.svg", format="svg")
  82. # Save as PNG
  83. g.savefig(f"{output_path}/{output_filename}.png", format="png")
  84. plt.show()