2016-04-07 20 views
1

İki sütun tweets ve score olan bir dataframe df_tweets var. Skor benR'de Naive Bayes, Sentiment analizi, sınıf hatası zorlanmasına neden olur

myPrediction<- predict(classifier,op) 

Error in as.data.frame.default(newdata) : 
cannot coerce class "c("DocumentTermMatrix", "simple_triplet_matrix")" to a data.frame 

Bunu nasıl çözebilirsiniz bir hatayı olsun

getMatrix <- function(chrVect){ 
testsource <- VectorSource(chrVect) 
testcorpus <- Corpus(testsource) 
testcorpus <- tm_map(testcorpus,stripWhitespace) 
testcorpus <- tm_map(testcorpus, removeWords, stopwords('french')) 
testcorpus <- tm_map(testcorpus, removeWords, stopwords('english')) 
testcorpus <- tm_map(testcorpus, content_transformer(tolower)) 
testcorpus <- tm_map(testcorpus, removePunctuation) 
testcorpus <- tm_map(testcorpus, removeNumbers) 
testcorpus <- tm_map(testcorpus, PlainTextDocument) 

return(DocumentTermMatrix(testcorpus)) 
} 

op =getMatrix(df_tweets$text) 
classifier <-naiveBayes(as.matrix(op), as.factor(df_tweets$avg_score)) 

Ben işlevini tahmin kullanmak 1 to 5 arasında değerlere sahip bir faktördür?

+0

Belki "as.data.frame" ile veya "as.matrix.data.frame' ile" as.matrix' wrap. ??? –

+0

Bu işe yaradı. Bunu bir cevap olarak gönderebilirsen kabul edebilirim/Ya da Mesajımı sil –

cevap

1

as.matrix'u as.data.frame ile veya doğrudan as.matrix.data.frame ile paketleyebileceğinize inanıyorum.

İlgili konular