全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2499 1
2016-10-23
本人使用randomForest包的rf算法
首先用
rf<-randomForest(mark~.,train,importance = T) 来生成模型

然后用rf.predict<-predict(rf,test)来进行预测
但是结果遇到错误:
Error in predict.randomForest(rf, test) :
  Type of predictors in new data do not match that of the training data.
但是我查看train 和 test 的类型
str(test)
'data.frame':        2967 obs. of  13 variables:
$ user_Id : num  7.13e+09 2.71e+08 8.02e+09 7.84e+09 8.02e+09 ...
$ mark    : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
$ Id_1_1  : Factor w/ 9 levels "1","2","3","4",..: 7 2 8 7 8 4 5 8 8 4 ...
$ Id_2_2  : Factor w/ 10 levels "0","1","2","3",..: 2 8 1 9 1 10 2 1 1 8 ...
$ Id_3_3  : Factor w/ 10 levels "0","1","2","3",..: 4 2 3 5 3 5 2 1 1 5 ...
$ Id_4_4  : Factor w/ 10 levels "0","1","2","3",..: 5 1 4 2 4 5 5 1 4 9 ...
$ Id_5_5  : Factor w/ 10 levels "0","1","2","3",..: 1 9 1 7 5 4 2 1 7 10 ...
$ Id_6_6  : Factor w/ 10 levels "0","1","2","3",..: 9 6 1 2 2 10 6 3 2 1 ...
$ Id_7_7  : Factor w/ 10 levels "0","1","2","3",..: 1 4 6 1 9 10 1 8 5 2 ...
$ Id_8_8  : Factor w/ 11 levels "","0","1","2",..: 2 5 5 2 4 7 2 2 4 3 ...
$ Id_9_9  : Factor w/ 11 levels "","0","1","2",..: 7 6 8 11 7 5 7 8 6 9 ...
$ Id_10_10: Factor w/ 9 levels "","0","1","2",..: 4 1 8 6 2 7 7 6 3 2 ...
$ digit   : int  10 9 10 10 10 10 10 10 10 10 ...
> str(train)
'data.frame':        6989 obs. of  13 variables:
$ user_Id : num  8.55e+09 6.18e+08 7.22e+09 4.63e+09 8.30e+09 ...
$ mark    : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
$ Id_1_1  : Factor w/ 9 levels "1","2","3","4",..: 8 6 7 4 8 7 1 6 5 2 ...
$ Id_2_2  : Factor w/ 10 levels "0","1","2","3",..: 6 2 3 7 3 10 9 1 2 6 ...
$ Id_3_3  : Factor w/ 10 levels "0","1","2","3",..: 5 8 3 4 10 6 6 7 4 2 ...
$ Id_4_4  : Factor w/ 10 levels "0","1","2","3",..: 7 8 3 3 10 9 9 9 1 1 ...
$ Id_5_5  : Factor w/ 10 levels "0","1","2","3",..: 10 2 6 1 5 2 10 10 3 1 ...
$ Id_6_6  : Factor w/ 10 levels "0","1","2","3",..: 3 9 1 1 3 2 1 1 3 6 ...
$ Id_7_7  : Factor w/ 11 levels "","0","1","2",..: 2 4 2 3 2 8 10 10 2 8 ...
$ Id_8_8  : Factor w/ 11 levels "","0","1","2",..: 2 7 2 5 2 7 4 4 2 3 ...
$ Id_9_9  : Factor w/ 11 levels "","0","1","2",..: 10 9 7 4 4 7 7 7 4 6 ...
$ Id_10_10: Factor w/ 9 levels "","0","1","2",..: 7 1 3 3 4 9 2 2 4 2 ...
$ digit   : int  10 9 10 10 10 10 10 10 10 10 ...


两者的内容类型应该一样啊,为什么会出这样的错误
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2020-12-8 13:34:54
请问楼主解决了吗?我也遇到同样的问题,苦恼中
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群