0

我是 R 新手,我尝试使用随机森林的客户评论进行情绪分析。

为此,我想使用 ngrams(bigrams 和 trigrams)作为特征(我使用了 quanteda R 包quanteda package

这是R代码:

train <- Data_clean[train.index, ]
test <- Data_clean[test.index, ]
grams <- train$Reviews %>% tokens(ngrams = 1:3) %>% # generate tokens
  dfm  # generate dfm


#Compute tf-idf, inverse document frequency, and relative term frequency on document-feature matrices
tf.idf.ngrams <- tfidf(grams, normalize = FALSE, scheme = "inverse")


# train random forest classifier

ndsi.forest <- randomForest(tf.idf.ngrams[train.index, ], as.factor(train$Note.Reco[train.index]), ntree = 100)

但是在构建随机森林分类器时出现错误:

> ndsi.forest <- randomForest(tf.idf.ngrams[train.index, ], as.factor(train$Note.Reco[train.index]), ntree = 100)
Error in t.default(x) : argument is not a matrix

你能帮我解决这个错误吗?

谢谢

4

0 回答 0