0% found this document useful (0 votes)
4 views2 pages

Clasification Tree With ROC

The document outlines a process for implementing Decision Tree Classification using a dataset on loan defaults. It includes steps for data preparation, such as encoding the target feature, splitting the dataset into training and test sets, and fitting different decision tree models. Additionally, it covers predicting outcomes, creating a confusion matrix, and visualizing the decision trees.

Uploaded by

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

Clasification Tree With ROC

The document outlines a process for implementing Decision Tree Classification using a dataset on loan defaults. It includes steps for data preparation, such as encoding the target feature, splitting the dataset into training and test sets, and fitting different decision tree models. Additionally, it covers predicting outcomes, creating a confusion matrix, and visualizing the decision trees.

Uploaded by

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

# Decision Tree Classification

# Importing the dataset


dataset = [Link]("[Link]", sep=",")
dataset = dataset[c(1,2,3,5)]

# Encoding the target feature as factor


dataset$Default = factor(dataset$Default,
levels = c('Yes', 'No'),
labels = c(1, 0))

# Splitting the dataset into the Training set and Test set
# [Link]('caTools')
library(caTools)
[Link](123)
split = [Link](dataset$Default, SplitRatio = 0.70)
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)

# Feature Scaling
#training_set[-4]= scale(training_set[-4])
#test_set[-4]= scale(test_set[-4])

# Fitting Decision Tree Classification to the Training set


#[Link]('rpart')
library(rpart)
classifier = rpart(formula = Default ~ .,
data = training_set,
parms = list(prior=c(0.75,0.25),split = "gini"))

classifier2 = rpart(formula = Default ~ .,


data = training_set)

classifier3 = rpart(formula = Default ~ .,


data = training_set,
control = [Link](minsplit = 2, cp = 0.01,
maxdepth = 3))
# Predicting the Test set results
y_pred = predict(classifier, newdata = test_set[-4], type = 'class')
y_pred
# Making the Confusion Matrix
cm = table(test_set[, 4], y_pred)
cm

# Plotting the tree


plot(classifier)
par(1,2)
text(classifier, pretty=0)

plot(classifier2)
par(1,2)
text(classifier2, pretty=0)

plot(classifier3)
par(1,2)
text(classifier3, pretty=0)

#ROC curve
[Link]("ROSE")
library(ROSE)
[Link](test_set$Default, y_pred)

You might also like