#pr3 decision tree classifier

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, StandardScaler
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
import seaborn as sns
import matplotlib.pyplot as plt

data = pd.read_csv("Admission_Predict.csv")

from sklearn.preprocessing import Binarizer
limit = Binarizer(threshold=0.75)
data["Chance of Admit "] = limit.fit_transform(data[["Chance of Admit "]])
print(data)


inputdata = data.drop(["Chance of Admit "], axis=1)
outputdata = data[["Chance of Admit "]]
print(inputdata)

print(outputdata)

outputdata = outputdata.astype(int)
print(outputdata)

x_train, x_test, y_train, y_test = train_test_split(
    inputdata, outputdata, test_size=0.25, random_state=0
)
print("✅ Training and testing split successful!")
print("Training set shape:", x_train.shape)
print("Testing set shape:", x_test.shape)

model = DecisionTreeClassifier(criterion='entropy', random_state=0)
model.fit(x_train, y_train)

y_pred = model.predict(x_test)


accuracy = accuracy_score(y_test, y_pred)
cm = confusion_matrix(y_test, y_pred)
report = classification_report(y_test, y_pred)
print("\n✅ Model Evaluation:")
print("Accuracy:", accuracy*100, "%")
print("\nConfusion Matrix:\n", cm)
print("\nClassification Report:\n", report)


sns.heatmap(cm, annot=True, fmt='d', cmap='Blues')
plt.title("Confusion Matrix - Decision Tree Classifier")
plt.xlabel("Predicted")
plt.ylabel("Actual")
plt.show()
