Ich hatte gehofft, Sie könnten in einer Text Mining Übung helfen. Ich war an AAPL-Tweets interessiert und konnte 500 Tweets aus der API ziehen. Ich konnte selbst einige Hürden überwinden, brauche aber Hilfe für den letzten Teil. Aus irgendeinem Grund entfernt das tm-Paket keine Stoppwörter. Können Sie bitte einen Blick darauf werfen, was das Problem sein könnte? Sind Emoticons ein Problem?Stock Tweets, Text Mining, Emoticon Erros
Nach Term_Frequency Plotten, sind die häufigsten Begriffe "AAPL", "Apple", "iPhone", "Preis", "Auf"
Vielen Dank im Voraus!
Munckinn
transform into dataframe
tweets.df <- twListToDF(tweets)
#Isolate text from tweets
aapl_tweets <- tweets.df$text
#Deal with emoticons
tweets2 <- data.frame(text = iconv(aapl_tweets, "latin1", "ASCII", "bye"), stringsAsFactors = FALSE)
#Make a vector source:
aapl_source <- VectorSource(tweets2)
#make a volatile corpus
aapl_corpus <- VCorpus(aapl_source)
aapl_cleaned <- clean_corpus(aapl_source)
#create my list to remove words
myList <- c("aapl", "apple", "stock", "stocks", stopwords("en"))
#clean corpus function
clean_corpus <- function(corpus){
corpus <- tm_map(corpus, stripWhitespace, mc.cores = 1)
corpus <- tm_map(corpus, removePunctuation, mc.cores = 1)
corpus <- tm_map(corpus, removeWords, myList, mc.cores = 1)
return(corpus)
}
#clean aapl corpus
aapl_cleaned <- clean_corpus(aapl_corpus)
#convert to TDM
aapl.tdm <- TermDocumentMatrix(aapl_cleaned)
aapl.tdm
#Convert as Matrix
aapl_m <- as.matrix(aapl.tdm)
#Create Frequency tables
term_frequency <- rowSums(aapl_m)
term_frequency <- sort(term_frequency, decreasing = TRUE)
term_frequency[1:10]
barplot(term_frequency[1:10])
Sein ist wahrscheinlich, weil "AAPL" und "AAPL" verschiedene Saiten sind. Ich sehe keinen "tolower" irgendwo in Ihrem Korpusreinigungsverfahren. Sie müssen 'corpus <- tm_map (corpus, content_transformer (tolower))' und 'corpus <- VCorpus (corpus) hinzufügen' Der zweite 'VCorpus' ist, weil der' content_transformer' einen Vektor anstelle eines Corpus, IIRC, zurückgibt. – emilliman5