我的数据框包含术语(列中)和每个单元格中的术语数。我想从train2数据框中选择最重要的术语(特征)。我正在使用Fselector库,如下所示:
library(dplyr)
library(party)
library(FSelector)
importance <- importance(train2)
varImportance <- data.frame(Variables = row.names(importance),
Importance= round(importance[,'MeanDecreaseGini'],2))
#Create a rank variable based on importance
rankImportance <- varImportance %>% mutate(
Rank = paste0('#',dense_rank(desc(Importance))))
ggplot(rankImportance,aes(x = reorder(Variables, Importance),
y = Importance, fill = Importance)) +
geom_bar(stat='identity') +
geom_text(aes(x = Variables, y = 0.5,label = Rank),
hjust=0, vjust=0.55,size = 4, colour = 'red') +
labs(x = 'Variables')+
coord_flip()
我收到了这个错误: UseMethod出错(&#34;重要性&#34;): 没有适用于“重要性”的方法适用于 课程对象&#34; c(&#39; tbl_df&#39;,&#39; tbl&#39;,&#39; data.frame&#39;)&#34;