如何在下面的代码中删除下标越界错误

时间:2018-04-02 12:06:08

标签: r text-mining

我试图编写如下代码但在分类器函数中有错误。我该如何编写此代码?有人可以帮忙吗?

library(RTextTools)
library(e1071)
library(SparseM)
library(naivebayes)
library(readr)
library(tm)
library(RWeka)
library(rJava)
library(corpus) ; library(corpustools) ; library(corpora)
pos_terms = read.csv("Positive terms.csv", header= TRUE)
pos_terms1 = as.matrix(pos_terms)
neg_terms = read.csv("Negative terms.csv", header= TRUE)
neg_terms1 = as.matrix(neg_terms)
test_terms = read_file("C:/Users/muj/Desktop/Test.txt")
test_terms = rbind(
       c('Fertilizer stocks surge'),
       c('Nifty drops below normal'),
       c('Stock market bulls at crucial juncture'),
       c('Markets crash'),
       c('Citi Bank stocks soar')
    )
test_terms1 = as.matrix(test_terms)

terms= rbind(pos_terms, neg_terms, test_terms)
myCorpus <- Corpus(VectorSource(terms)) 
dtm <-DocumentTermMatrix(myCorpus)
dtm = as.matrix(dtm)
classifier = naiveBayes(dtm[1:31,], as.factor(terms[1:31,2])) 
  

dtm [1:37,]:下标超出范围

时出错
predicted = predict(classifier, mat[27:31,]); predicted
  

mat [27:31,]中的错误:下标超出界限

table(terms[27:31,2],predicted)
  

术语错误[27:31,2]:下标超出范围

recall_accuracy(terms[27:31,2], predicted)
  

术语错误[27:31,2]:下标超出范围

0 个答案:

没有答案