cart-elc

Source code for CART-ELC
git clone git://git.laack.co/cart-elc.git
Log | Files | Refs | README | LICENSE

dia3.py (1319B)


      1 import pandas as pd
      2 import numpy as np
      3 import matplotlib.pyplot as plt
      4 
      5 # Dark mode settings using matplotlib only
      6 # plt.rcParams.update({
      7 #     "axes.facecolor": "#000000",
      8 #     "axes.edgecolor": "#333333",
      9 #     "figure.facecolor": "#000000",
     10 #     "savefig.facecolor": "#000000",
     11 #     "text.color": "white",
     12 #     "axes.labelcolor": "white",
     13 #     "xtick.color": "white",
     14 #     "ytick.color": "white",
     15 #     "grid.color": "gray",
     16 #     "axes.grid": True
     17 # })
     18 
     19 df = pd.read_csv('./diabetes.csv')
     20 X = df['BMI'].to_numpy()
     21 y = df['Outcome'].to_numpy()
     22 
     23 # Create a scatter plot using matplotlib only
     24 plt.figure(figsize=(10, 6))
     25 plt.scatter(X, y, c=y, cmap='bwr', s=40, edgecolors='#000000')
     26 
     27 plt.xlabel("BMI")
     28 plt.ylabel("Diagnosis")
     29 
     30 plt.axvspan(0, 32.25, color='blue', alpha=0.3)  # Light blue to the left
     31 plt.axvspan(32.25, 50, color='red', alpha=0.3)  # Light red to the right
     32 
     33 plt.axvline(32.25, color="black", linestyle="-")
     34 
     35 
     36 plt.xlim([0, 50])
     37 plt.tight_layout()
     38 
     39 # Save the figure instead of displaying it
     40 plt.savefig("dia3.pdf")
     41 
     42 plt.close()  # Closes the plot so it doesn't display or use memory
     43 
     44 # Calculate classification accuracy based on threshold
     45 wrong = 0
     46 for i in range(len(X)):
     47     if (y[i] == 1 and X[i] < 32.25) or (y[i] == 0 and X[i] > 32.25):
     48         wrong += 1
     49 
     50 print((len(X) - wrong) / len(X))