R 决策树总是预测类标签为Yes

R 决策树总是预测类标签为Yes,r,machine-learning,decision-tree,R,Machine Learning,Decision Tree,我试图在R中的一个小数据集上拟合决策树模型,但它总是预测类标签为“是”,而不管我输入的数据集是什么 资料 预测函数总是给出“是”的结果,与输入无关 问题出在哪里?对于这样一个小的训练集,您需要更新模型控件,并对结果稍加考虑 model <- rpart(class ~ ., data = data, control = rpart.control(minsplit = 1)) predict(model, newdata = data, type = 'class') # 1 2

我试图在R中的一个小数据集上拟合决策树模型,但它总是预测类标签为“是”,而不管我输入的数据集是什么

资料

预测函数总是给出“是”的结果,与输入无关


问题出在哪里?

对于这样一个小的训练集,您需要更新模型控件,并对结果稍加考虑

model <- rpart(class ~ ., data = data, control = rpart.control(minsplit = 1))
predict(model, newdata = data, type = 'class')
#   1   2   3   4   5   6   7   8   9  10  11  12  13  14 
#  no  no yes yes yes  no yes  no yes yes yes yes yes  no 
# Levels: no yes

model您的模型找不到任何拆分。可能重复:明白了。非常感谢。
outlook_new <- as.numeric(as.factor(outlook))
temperature_new <- as.numeric(as.factor(temperature))
humidity_new <- as.numeric(as.factor(humidity))
wind_new <- as.numeric(as.factor(wind))
class_new <- as.numeric(as.factor(class))

data_new <- data.frame(outlook_new, temperature_new, humidity_new, wind_new, class_new)
data_new
model <- rpart(class_new ~ ., data=data_new)
test_data <- data.frame(outlook_new = 2, temperature_new = 2, humidity_new = 1, wind_new = 1)
test_data
predict(model, test_data, type='response')
model <- rpart(class ~ ., data = data, control = rpart.control(minsplit = 1))
predict(model, newdata = data, type = 'class')
#   1   2   3   4   5   6   7   8   9  10  11  12  13  14 
#  no  no yes yes yes  no yes  no yes yes yes yes yes  no 
# Levels: no yes