繁体   English   中英

错误:矩阵必须具有相等的维度

[英]error : Matrix must have equal dimensions

我一直在尝试这个。 Model 不能给我混淆矩阵

    fit <- rpart(taste ~ ., data = train,method="class",control = rpart.control(cp = 0.01)) 
    summary(fit)



    knn_prediction <- predict(fit, test)
    confusionMatrix(knn_prediction, test$taste)

#when I tried the confusion matrix 它给了我错误:matrix must have equal dimensions

predict.raprt type的默认参数是prob ,它使您的矩阵成为knn_prediction

您应该使用type = "class"来为您的代码创建混淆矩阵。

尝试

knn_prediction <- predict(fit, test, type = "class")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM