# !pip install numpy pandas matplotlib seaborn scikit-learn scipy
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn import metrics

# Updated dataset
data = {
    'Patient': ['Small', 'Medium', 'Senior', 'Small', 'Small', 'Senior', 'Medium', 'Senior', 'Medium', 'Medium', 'Senior'],
    'Disease': ['Serious', 'Normal', 'Lifetime', 'Lifetime', 'Normal', 'Serious', 'Serious', 'Normal', 'Lifetime', 'Serious', 'Normal'],
    'Sugar Level': ['High', 'Low', 'Normal', 'High', 'High', 'Normal', 'Low', 'Low', 'Normal', 'High', 'High'],
    'Survival Chance?': ['Yes', 'Yes', 'Yes', 'No', 'Yes', 'No', 'Yes', 'No', 'Yes', 'No', 'yes']
}

df = pd.DataFrame(data)

# Map categorical variables to numeric
df['Patient'] = df['Patient'].map({'Small': 0, 'Medium': 1, 'Senior': 2})
df['Disease'] = df['Disease'].map({'Normal': 0, 'Serious': 1, 'Lifetime': 2})
df['Sugar Level'] = df['Sugar Level'].map({'Low': 0, 'Normal': 1, 'High': 2})
df['Survival Chance?'] = df['Survival Chance?'].str.lower().map({'no': 0, 'yes': 1})

X = df[['Patient', 'Disease', 'Sugar Level']]
y = df['Survival Chance?']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)

clf = DecisionTreeClassifier(max_depth=3)
clf1 = clf.fit(X_train, y_train)
y_pred = clf1.predict(X_test)

print("Accuracy: ", metrics.accuracy_score(y_test, y_pred))

from matplotlib import pyplot as plt
from sklearn import tree

fig = plt.figure()
tree.plot_tree(clf1)
plt.show()
plt.savefig('dt_image.png')
