1
Ich habe einen Datenrahmen df_tweets
, die zwei Spalten tweets
und score
hat. Score ist ein Faktor, mit Werten zwischen 1 to 5
Naive Bayes in R, Sentiment-Analyse führt zu Klassenfehler nicht erzwingen
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))
Wenn ich die Funktion vorhersagen, verwende ich einen Fehler
myPrediction<- predict(classifier,op)
Error in as.data.frame.default(newdata) :
cannot coerce class "c("DocumentTermMatrix", "simple_triplet_matrix")" to a data.frame
Wie kann ich dieses Problem lösen?
Vielleicht wrap 'as.matrix' mit' as.data.frame' oder direkt mit 'as.matrix.data.frame' ??? –
Das hat funktioniert. Wenn Sie das als Antwort posten können, kann ich es akzeptieren/Oder meinen Beitrag löschen –