0% found this document useful (0 votes)
23 views

Assignment - 4 - Decision Tree - 014319

Decision tree ml

Uploaded by

vedikadhebe2712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Assignment - 4 - Decision Tree - 014319

Decision tree ml

Uploaded by

vedikadhebe2712
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment No.

Roll no. - 33309

[2]: import numpy as np


import pandas as pd

[3]: dataset = pd.read_csv("admission_data.csv")

[7]:

[7]: Serial No. GRE Score TOEFL Score University Rating SOP LOR CGPA \
0 1 337 118 4 4.5 4.5 9.65
1 2 324 107 4 4.0 4.5 8.87
2 3 316 104 3 3.0 3.5 8.00
3 4 322 110 3 3.5 2.5 8.67
4 5 314 103 2 2.0 3.0 8.21

Research Chance of Admit


0 1 1.0
1 1 0.0
2 1 0.0
3 1 1.0
4 0 0.0

[8]:

[8] : Serial No. 0


GRE Score 0
TOEFL Score 0
University Rating 0
SOP 0
LOR 0
CGPA 0
Research 0
Chance of Admit 0
dtype: int64

[9] : dataset.columns

1
[9] : Index(['Serial No.', 'GRE Score', 'TOEFL Score', 'University Rating', 'SOP',
'LOR ', 'CGPA', 'Research', 'Chance of Admit '],
dtype='object')

[10] : dataset.loc[dataset['Chance of Admit < 0.8, 'Chance of Admit = 0


dataset.loc[dataset['Chance of Admit >= 0.8, 'Chance of Admit =1

[11] : X = Admit =
y= Admit

[12] : from sklearn.model_selection import train_test_split


=
‹→random_state = 123)

[15]: from sklearn.tree import DecisionTreeClassifier, plot_tree


from sklearn import metrics

dtc = DecisionTreeClassifier()

dtc = dtc.fit(X_train, Y_train)

y_pred = dtc.predict(X_test)

print("Confusion Matrix: \n")


print(metrics.confusion_matrix(Y_test, y_pred))
print("\n1. Accuracy Score:\t", metrics.accuracy_score(Y_test, y_pred))
print("2. Precision Score:\t",metrics.precision_score(Y_test, y_pred))
print("3. Recall Score:\t", metrics.recall_score(Y_test, y_pred))
print("4. f1 Score:\t", metrics.f1_score(Y_test, y_pred))

Confusion Matrix:

[[79 3]
[ 4 39]]

1. Accuracy Score: 0.944


2. Precision Score: 0.9285714285714286
3. Recall Score: 0.9069767441860465
4. f1 Score: 0.9176470588235294

[19]:
plot_tree(dtc, feature_names=X.columns, class_names=['0', '1'], filled=True)

2
3

You might also like