0% found this document useful (0 votes)
75 views3 pages

Decision Tree for Admission Prediction

This document discusses using a decision tree classifier on student admission data. The data is preprocessed by separating it into training and test sets, normalizing features, and labeling samples as 1 if the chance of admission is over 80% or 0 if less than or equal to 80%. A decision tree classifier is fit to the training data and used to make predictions on the test set. Various evaluation metrics like accuracy, confusion matrix, precision, recall and F1 score are calculated to analyze the classifier's performance on both training and test sets.

Uploaded by

06–Yash Bhusal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views3 pages

Decision Tree for Admission Prediction

This document discusses using a decision tree classifier on student admission data. The data is preprocessed by separating it into training and test sets, normalizing features, and labeling samples as 1 if the chance of admission is over 80% or 0 if less than or equal to 80%. A decision tree classifier is fit to the training data and used to make predictions on the test set. Various evaluation metrics like accuracy, confusion matrix, precision, recall and F1 score are calculated to analyze the classifier's performance on both training and test sets.

Uploaded by

06–Yash Bhusal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# Assignment 3: Classification using Decision Tree

import pandas as pd import numpy as np import


[Link] as plt import seaborn as sns

# %% [markdown]
# ## Prediction Models : Classification Algorithm (Supervised Machine
Learning)
#
# 4. Decision Tree Classification

# %% [markdown]
# ### Preparing Data for Classification

# %% [markdown]
# If a candidate's Chance of Admit is greater than 80%, the candidate
will receive the 1 label.
#
# If a candidate's Chance of Admit is less than or equal to 80%, the
candidate will receive the 0 label.

# %% [code]
# reading the dataset
df = pd.read_csv("Admission_Predict.csv")
print("shape of dataset",[Link])

# %% [code]
# it may be needed in the future.
serialNo = df["Serial No."].values
[Link](["Serial No."], axis=1, inplace=True)

df = [Link](columns={'Chance of Admit ': 'Chance of Admit'})

# %% [code]
X = [Link](["Chance of Admit"], axis=1)
y = df["Chance of Admit"].values

# %% [code]
# separating train (80%) and test (%20) sets from
sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y,


test_size=0.20, random_state=101)

# %% [code] #
normalization
from [Link] import MinMaxScaler

scalerX = MinMaxScaler(feature_range=(0, 1))


X_train[X_train.columns] =
scalerX.fit_transform(X_train[X_train.columns])
X_test[X_test.columns] = [Link](X_test[X_test.columns])

# %% [code]
y_train_01 = [1 if each > 0.8 else 0 for each in y_train]
y_test_01 = [1 if each > 0.8 else 0 for each in y_test]

# list to array
y_train_01 = [Link](y_train_01)
y_test_01 = [Link](y_test_01)

# %% [markdown]
# ### 4. Decision Tree Classification

# %% [code]
from [Link] import DecisionTreeClassifier
dtc = DecisionTreeClassifier()
[Link](X_train, y_train_01)
y_pred_dtc = [Link](X_test)
print("score: ", [Link](X_test, y_test_01))

# %% [code] #
confusion matrix
from [Link] import confusion_matrix

cm_dtc = confusion_matrix(y_test_01, y_pred_dtc)


print("confusion matrix for test data:decision tree\n",cm_dtc) #
print("y_test_01 == 1 :" + str(len(y_test_01[y_test_01==1]))) # 29
cm_dtc
# %% [code] # cm visualization
import seaborn as sns import
[Link] as plt

f, ax = [Link](figsize=(5, 5))
[Link](cm_dtc, annot=True, linewidths=0.5, linecolor="red",
fmt=".0f", ax=ax)
[Link]("Test for Test Dataset:decision tree")
[Link]("predicted y values")
[Link]("real y values")
[Link]()
# %% [code]
from [Link] import precision_score, recall_score
print("precision_score: ", precision_score(y_test_01,
y_pred_dtc)) print("recall_score: ", recall_score(y_test_01,
y_pred_dtc))

from [Link] import f1_score

print("f1_score: ", f1_score(y_test_01, y_pred_dtc))


# %% [markdown]
# Test for Train Dataset:

# %% [code]
cm_dtc_train = confusion_matrix(y_train_01, [Link](X_train))
print("confusion matrix for test data:decision tree\n",cm_dtc_train)
f, ax = [Link](figsize=(5, 5))
[Link](cm_dtc_train, annot=True, linewidths=0.5, linecolor="red",
fmt=".0f", ax=ax)

You might also like