列'A'的值为0,1,2。根据其他数据列,我应该预测'A'的值我正在使用rpart()函数,但是我在输出中得到小数值(0.3961,0.688,0.012等,当我绘制树时)而不是自然数字(0,1,2)
formulaA = A ~ car_value + car_age + age_oldest + age_youngest + duration_previous + group_size + homeowner + risk_factor + married_couple
fit = rpart(formulaA, method = "class", data = trainNONA0)
plot(fit) # plotting the tree so that I can see the classification and the nodes.
text(fit) # labeling the tree
数据框包含以下列: customer_ID group_size homeowner car_age car_value risk_factor age_oldest age_youngest married_couple C_previous duration_previous A B C D
我应该使用其他属性来预测A,B,C和D.我试图单独预测它们(因为我们无法使用决策树预测多个属性)。输出应该是自然数。 A可以有0,1,2; B-0,1; C-1,2,3,4和D-1,2,3。以下是A,B,C,D的样本值。 {1 0 2 2; 1 0 2 2; 1 0 2 2; 0 0 3 2; 0 0 3 2; 0 0 3 2; 0 0 2 3; 1 1 3 2; 1 1 3 2; 1 1 3 3; 2 1 1 1; 1 1 1 1; 1 1 1 1;}
因此,结束节点应为0或1或2,但该图给出结束节点为(0.3961,0.688,0.012等)
答案 0 :(得分:0)
尝试 预测(fit,type =“class”) 得到预测的类而不是类概率的向量。
以下是一个例子:
> data(cars)
> m<-rpart(speed~dist, data=cars)
> predict(m, type="class")
Error in predict.rpart(m, type = "class") :
Invalid prediction for "rpart" object
> # Doesn't work
> m<-rpart(speed~dist, data=cars, method="class")
> predict(m, type="class")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
12 12 12 12 12 12 12 12 13 12 12 12 12 12 12 12 13 13 13 12 13 20 24 12 12 20 ...