【发布时间】:2021-06-17 03:53:08
【问题描述】:
在我的dataset 中,我有一个二进制Target(0 或1)变量和8 个特征:nchar、rtc、Tmean、week_day、hour、ntags、 nlinks 和 nex。 week_day 是一个因素,而其他因素是数字。我正在尝试构建一个决策树分类器:
library(caTools)
set.seed(123)
split = sample.split(dataset$Target, SplitRatio = 0.75)
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
# Feature Scaling
training_set[-c(2,4)] = scale(training_set[-c(2,4)])
test_set[-c(2,4)] = scale(test_set[-c(2,4)])
# Fitting Decision Tree Classification to the Training set
# install.packages('rpart')
library(rpart)
classifier = rpart(formula = Target ~ .,
data = training_set)
# Predicting the Test set results
y_pred = predict(classifier, newdata = test_set[-2], type = 'class')
# Making the Confusion Matrix
cm = table(test_set[, 2], y_pred)
plot(classifier, uniform=TRUE,margin=0.2)
绘图结果如下:
我有三个我不知道答案的问题:
- 为什么图中缺少一些变量? (例如
rtc) -
week_day中的aefg是什么意思? - 有没有办法描述
不同的类(
Target变量的 0 对 1)?例如: 在Target=1我们有所有具有nchar>0.19的行和ntags>1.9等
【问题讨论】:
标签: r decision-tree