# 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)