• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 11 pages
Summary

Summary SOFTWARE E H202 Programmeren 3

Document preview thumbnail
Preview 2 out of 11 pages

SOFTWARE E H202 Programmeren 3 Opgave 4 Analytics 2019 Naam student: graag hier invullen Data voor deze opgave: (documentatie: ). Inleveren Inleveren UITSLUITEND via Blackboard. Uiterste datum van inleveren: 24-3-2019. Inleveren UITSLUITEND in formaat .PDF, .DOC of .DOCX. Als je met RStudio werkt kan je de .Rmd file als basis gebruiken. Anders mag je de resultaten in dit document opnemen. Vergeet niet je naam in het document te zetten. Inleiding De opgave gaat over het analyseren van tweets. De vraag is om vast te stellen of een tweet een positieve dan wel een negatieve lading heeft. Bij deze opgave begin je met ruwe data. In de data staan een aantal variabelen die je waarschijnlijk beter niet kan gebruiken. Het kan zij dat een aantal tweets meerdere malen voorkomt. (Misschien is het beter om deze teksten eerst te ontdubbelen, misschien maakt dat ook niet zo veel uit) Het is aan jou om deze data zodanig te behandelen dat je de analyse goed kan uitvoeren. De afhankelijke variabele is “Sentiment”. De vraag is om een zo goed mogelijk CART-tree model te maken om uit de tekst van een tweet op te maken of het een positieve of negatieve lading heeft. De methode (text analytics) is uitgelegd op het college en is ook te vinden in de video’s “Turning Tweets into Knowledge”. Bij deze opgave wordt van je verwacht dat je zelf de juiste stappen zet om tot het gewenste eindresultaat te komen. Probeer zo goed mogelijk uit te leggen WAAROM je bepaalde stappen zet. Vraag 1 Maak een zo optimaal mogelijk CART-tree model om uit de tekst van een tweet het (positieve/negatieve) sentiment te halen. Let op: de Sentiment-variabele heeft DRIE verschillende waarden. Maak hiervan eerst een factor met slechts TWEE categorieen (positief/negatief). (Om te zorgen dat het een factor wordt kan je de functie r gebruiken). Gebruik daarvoor de tekst-analyse methodiek uit het college en/of de video’s. Zorg er ook voor dat je de data splitst in een trainingsset en een testset, zodat je de validatie goed kan uitvoeren. In je antwoorddocument verwacht ik in elk geval: - Alle R-commando’s - Relevant commentaar zodat het duidelijk is wat je doet en waarom je het doet - Alle relevante R-uitvoer (bijvoorbeeld confusion matrices) - Alle relevante R-plots - Niet alleen het opstellen van een model (op basis training data) maar ook validatie van het model (op basis van testdata). Validatie bestaat in elk geval uit confusion matrix + accuracy + sensitivity + specificity en een ROC-curve, plus een argumentatie over hoe goed het model de betreffende data kan voorspellen. - Een goed onderbouwde conclusie setwd("D:/Documents/School/Jaar 2 Periode 3/Analytics") getwd function () .Internal(getwd()) bytecode: 0xdf2c900 environment: namespace:base tweets - ("", stringsAsFactors=FALSE) stringsAsFactors moet op false, zodat de tekst goed kan worden verwerkt. str(tweets) '': 498 obs. of 6 variables: $ Sentiment: int 4 4 4 4 4 4 0 4 4 4 ... $ ID : int 3 4 5 6 7 ... $ Date : chr "Mon May 11 03:17:40 UTC 2009" "Mon May 11 03:18:03 UTC 2009" "Mon May 11 03:18:54 UTC 2009" "Mon May 11 03:19:04 UTC 2009" ... $ Query : chr "kindle2" "kindle2" "kindle2" "kindle2" ... $ User : chr "tpryan" "vcu451" "chadfu" "SIX15" ... $ Tweet : chr "@stellargirl I loooooooovvvvvveee my Kindle2. Not that the DX is cool, but the 2 is fantastic in its own right." "Reading my kindle2... Love it... Lee childs is good read." "Ok, first assesment of the #kindle2 ...it fucking rocks!!!" "@kenburbary You'll love your Kindle2. I've had mine for a few months and never looked back. The new big one is "| truncated ... Er zijn 498 observaties. Er staat per tweet welk sentiment de tweet heeft, het ID, de datum van de post, de query waarop is gezocht, de twitteraar en de tweet zelf. tweets$Negative = r(tweets$Sentiment = 0) table(tweets$Negative) FALSE TRUE 321 177 Er wordt een variabele Negative gemaakt, die wordt gelijk aan 0 gezet. In de table is te zien dat er 177 negatieve tweets in de dataset zitten. ges("tm") library(tm) ges(“SnowballC”) library(SnowballC) Er worden packages gedownload om de tekst analyse te maken corpus - VCorpus(VectorSource(tweets$Tweet)) corpus VCorpus Metadata: corpus specific: 0, document level (indexed): 0 Content: documents: 498 Er wordt een corpus gemaakt om de tekst te verwerken. De functie VCorpus wordt gebruikt, omdat elke tweet in een vector staat. Als het niet zo wordt gedaan, werkt de tm_map functie niet. corpus[[1]] PlainTextDocument Metadata: 7 Content: chars: 111 Er wordt getest of de corpus klopt. We printen de eerste tweet. corpus = tm_map(corpus, tolower) corpus[[1]] [1] "@stellargirl i loooooooovvvvvveee my kindle2. not that the dx is cool, but the 2 is fantastic in its own right." Met tm_map zetten we alle tweets om naar lowercase. Daarna wordt er gekeken of het inderdaad werkt. corpus = tm_map(corpus, removePunctuation) corpus[[1]] [1] "stellargirl i loooooooovvvvvveee my kindle2 not that the dx is cool but the 2 is fantastic in its own right" Met de removePunctuation functie worden alle leestekens weggehaald. corpus = tm_map(corpus, removeWords, stopwords("english")) corpus[[1]] [1] "stellargirl loooooooovvvvvveee kindle2 dx cool 2 fantastic right" Met removeWords zijn de Engelse stopwoorden uit de tweet gehaald. corpus = tm_map(corpus, stemDocument) corpus[[1]] [1] "stellargirl loooooooovvvvvvee kindle2 dx cool 2 fantast right" Met stemDocument worden de vervoegingen van alle woorden weggehaald om de tekst te generaliseren. corpus - tm_map(corpus, PlainTextDocument) Door de tolower functie is het corpus een ander datatype geworden. Deze functie zet het weer terug naar een PlainTextDocument. frequencies- DocumentTermMatrix(corpus) frequencies DocumentTermMatrix (documents: 498, terms: 1872) Non-/sparse entries: 3992/ Sparsity : 100% Maximal term length: 46 Weighting : term frequency (tf) Deze functie laat zien hoeveel bepaalde woorden er in het corpus voorkomen inspect(frequencies[50:60,300:308]) DocumentTermMatrix (documents: 11, terms: 11) Non-/sparse entries: 0/121 Sparsity : 100% Maximal term length: 11 Weighting : term frequency (tf) Sample : Terms Docs cell ceo chang channel charact charad chariti chart character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 character(0) 0 0 0 0 0 0 0 0 Met inspect wordt er gespit in tweets 50 tot 60 voor woorden 300 tot 308. findFreqTerms(frequencies, lowfreq = 20) [1] "get" "good" "googl" "got" "great" "hate" "jqueri" [8] "just" "kindle2" "lebron" "love" "museum" "new" "night" [15] "nike" "safeway" "see" "time" "twitter" "warner" Nu worden alle woorden die meer dan 20 keer voorkomen geprint. sparse - removeSparseTerms(frequencies, 0.995) sparse DocumentTermMatrix (documents: 498, terms: 316) Non-/sparse entries: 2200/ Sparsity : 99% Maximal term length: 27 Weighting : term frequency (tf) Met sparse wordt 0,5% van de woorden in de matrix gehouden. De overige 99,5% komt te weinig voor en wordt dus uit de matrix gehaald. Er zijn nu nog 316 woorden over. tweetsSparse - (x(sparse)) Sparse wordt in een dataframe genaamd tweetsSparse gezet. colnames(tweetsSparse) - (colnames(tweetsSparse)) Dit geeft alle variabelen goede namen om de data goed te verwerken. tweetsSparse$Negative - tweets$Negative Zet de eerste vorm van Negative naar de nieuwe vorm van Negative. library(caTools) (123) split = (tweetsSparse$Negative, SplitRatio = 0.7) Data splitten, met 70% data in de trainingsset. trainSparse = subset(tweetsSparse, split==TRUE) testSparse = subset(tweetsS


Document information

Uploaded on
May 23, 2022
Number of pages
11
Written in
2021/2022
Type
Summary
$20.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Tutorson
4.1
(17)
Sold
122
Followers
121
Items
540
Last sold
9 months ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions

Whoops! We can’t load your doc right now. Try again or contact support.