【发布时间】:2017-12-17 01:22:28
【问题描述】:
由于为 Fisher 的虹膜数据创建决策树,我得到了错误分类错误率:0.02667 = 4 / 150。但我在我的图中只看到 3 个错误: DS for the iris.
如果我们查看这一点的概率 - 没关系(弗吉尼亚州 - 与上图相同):
setosa versicolor virginica
0 0.1666667 0.83333333
你能解释一下为什么会发生这种错误分类(4 个错误,而不是图中清楚描绘的 3 个)吗?
代码:
# install.packages("tree")
# install.packages("ggplot2")
library('tree')
library('ggplot2')
data(iris)
iris <- iris[ , c('Petal.Length', 'Petal.Width', 'Species')]
myTree <- tree(Species ~ Petal.Length + Petal.Width, data = iris)
summary(myTree)
# Classification tree:
# tree(formula = Species ~ Petal.Length + Petal.Width, data = iris)
# Number of terminal nodes: 5
# Residual mean deviance: 0.157 = 22.77 / 145
# Misclassification error rate: 0.02667 = 4 / 150
# The errors were found by comparing predict(myTree, iris, type="class")
# with native data set
errors <- data.frame(
Species = c('versicolor', 'versicolor', 'versicolor', 'virginica'),
Petal.Length = c(4.8, 5.0, 5.1, 4.5), Petal.Width = c(1.8, 1.7, 1.6, 1.7))
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) +
geom_point(size = 2.1) +
geom_vline(xintercept = 2.45) +
geom_hline(yintercept = 1.75) +
geom_vline(xintercept = 4.95) +
geom_point(data = errors, shape = 1, size = 5,colour = "black")
【问题讨论】:
-
您将需要共享用于构建模型并获得预测的代码。否则我们能做的最好的就是说你要么编码错误,要么解释了一些输出错误。
-
请指定您使用的任何包并包括加载它们的代码。旁注:你为什么称树DT?通常这意味着该对象是一个 data.table。还要说明你是如何确定你认为哪些是错误分类的。
-
我建议添加用于制作图表的代码和用于确定哪些被错误分类的代码。请注意,花瓣长度 = 4.8 和花瓣宽度 = 1.8 的观察结果不止一个
-
...我不希望您手动构建错误数据帧。这根本没有帮助 - 我试图让你展示你用来找出哪些错误的代码......无论哪种方式 - 看看我的答案 - 没有出错。
标签: r statistics decision-tree