cart-elc

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

dia4.py (1219B)


      1 import pandas as pd
      2 import matplotlib.pyplot as plt
      3 import numpy as np
      4 from sklearn import tree
      5 from sklearn import metrics
      6 
      7 # Dark mode settings using matplotlib only
      8 # plt.rcParams.update({
      9 #     "axes.facecolor": "#000000",
     10 #     "axes.edgecolor": "#333333",
     11 #     "figure.facecolor": "#000000",
     12 #     "savefig.facecolor": "#000000",
     13 #     "text.color": "white",
     14 #     "axes.labelcolor": "white",
     15 #     "xtick.color": "white",
     16 #     "ytick.color": "white",
     17 #     "grid.color": "gray",
     18 #     "axes.grid": True
     19 # })
     20 
     21 df = pd.read_csv('./diabetes.csv')
     22 X = df['BMI']
     23 y = df['Glucose']
     24 color = df['Outcome']
     25 
     26 xSub = []
     27 ySub = []
     28 X = X.to_numpy()
     29 y = y.to_numpy()
     30 
     31 # Create scatter plot with dark styling
     32 plt.figure(figsize=(10, 6))
     33 plt.scatter(X, y, c=color, cmap='bwr', s=60, edgecolors="#000000")
     34 plt.xlabel("BMI")
     35 plt.ylabel("Glucose")
     36 plt.xlim([0, 50])
     37 plt.tight_layout()
     38 
     39 # Save the graph as dia4.pdf
     40 plt.savefig("dia4.pdf")
     41 plt.close()
     42 
     43 # Decision Tree for prediction
     44 targ = []
     45 
     46 for i in range(0, len(X)):
     47     targ.append([X[i], y[i]])
     48 
     49 dt = tree.DecisionTreeClassifier(max_depth=5)
     50 dt.fit(targ, color)
     51 preds = dt.predict(targ)
     52 
     53 # Print the accuracy score
     54 print(metrics.accuracy_score(y_pred=preds, y_true=color))