全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
8488 2
2015-11-25
> write.csv(submission, file = "D:/Kaggle/1_random_forest_r_submission.csv", row.names=FALSE)
>
> imp <- importance(rf, type=1)
> featureImportance <- data.frame(Feature=row.names(imp), Importance=imp[,1])
> p <- ggplot(imp, aes(x=reorder(Feature,Importance), y=Importance) )
错误: ggplot2 doesn't know how to deal with data of class matrix
>             +
+   geom_bar() +   
+   coord_flip() +
+   theme_light(base_size=20) +
+   xlab("") +
+   ylab("Importance")
错误于+geom_bar() : 一进列运算符的参数不对
>   ggtitle("Random Forest Feature Importance\n") +
+   theme(plot.title=element_text(size=18))
错误: 没有"ggtitle"这个函数
>
> ggsave("2_feature_importance.png", p)

运行的   Kagg'le里的一个R语言的例子  我明明featureImportance是data.frame 类型 数据 为什么会出现错误: ggplot2 doesn't know how to deal with data of class matrix

二维码

扫码加我 拉你入群

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

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

全部回复
2015-11-25 12:02:17
在ggplot2 中,所有函数中data 变量,均要data.frame 类型!!!
因此,将matrix 用as.data.frame 转为data.frame
因为 Hadley Wickham 推崇data.frame 所至,他开发的packages 大都如此!!
二维码

扫码加我 拉你入群

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

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

2015-11-25 15:37:57
jgchen1966 发表于 2015-11-25 12:02
在ggplot2 中,所有函数中data 变量,均要data.frame 类型!!!
因此,将matrix 用as.data.frame 转为dat ...
粗心了  变量写错了
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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