You are on page 1of 20

2/7/2020 Final-Project---Knit.utf8.

md

Final-Project—Knit.R
Prashant Gupta
2020-02-07

setwd("C:/Users/Prashant Gupta/Desktop/Data File")

library(SnowballC)
library(tm)

## Warning: package 'tm' was built under R version 3.6.1

## Loading required package: NLP

library(twitteR)

## Warning: package 'twitteR' was built under R version 3.6.1

library(wordcloud)

## Warning: package 'wordcloud' was built under R version 3.6.1

## Loading required package: RColorBrewer

library(RColorBrewer)
library(syuzhet)

## Warning: package 'syuzhet' was built under R version 3.6.1

mother <- read.csv("Cloudnine_Mumbai.csv")


head(mother)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 1/20


2/7/2020 Final-Project---Knit.utf8.md

##
Reviews
## 1 I went to Dr. Saloni for a regular check-up before we were planning for a baby and it tu
rned out to be the best decision of my life. We had a long but fruitful journey with her. Bec
ause of all the care and guidance of Dr. Saloni, we are blessed with a healthy baby girl. I w
asn't a straightforward case to handle, but she managed all my complications like a pro. Righ
t from pre conception to post delivery she has been just amazing. The fact that she is access
ible over a phone helped me to put all my worries to end. She personally kept track of my pro
gress and health conditions regularly. The quality of care and level of support that Dr. Salo
ni provides is unmatched. She is an absolute angel.
## 2
My dream of motherhood has come true because of her and we are eternally grateful to her.
## 3
It was a great experience when we first met Dr. Datar. My wife was little tense to visit a ma
le gynecologist but after his understanding to the patient and accurate consultation with a b
ig smile, make it easy for a pregnant woman. From day 1 to delivery, he guided my wife very w
ell and give a strong mental support for her problems during pregnancy. He encouraged her to
give natural birth and never pushed us for c- section even we touched our due date for delive
ry.
## 4
In his consultation, today we are blessed with a baby girl with normal delivery and my wife h
as no complications.
## 5
Thanks to Dr. Nikhil Datar to give us always a positive guidance and consultation to make our
9 months journey safer and smoother.
## 6
I will recommend to everyone for any gynaecology issue, plz visit him for your happiness
??????

names(mother)<-"Review"

mother1 <- data.frame(mother$Review)


names(mother1) <-"Reviews"

mother.corpus <- Corpus(VectorSource(mother1$Reviews))


inspect(mother.corpus[1:5])

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 2/20


2/7/2020 Final-Project---Knit.utf8.md

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] I went to Dr. Saloni for a regular check-up before we were planning for a baby and it
turned out to be the best decision of my life. We had a long but fruitful journey with her. B
ecause of all the care and guidance of Dr. Saloni, we are blessed with a healthy baby girl. I
wasn't a straightforward case to handle, but she managed all my complications like a pro. Rig
ht from pre conception to post delivery she has been just amazing. The fact that she is acces
sible over a phone helped me to put all my worries to end. She personally kept track of my pr
ogress and health conditions regularly. The quality of care and level of support that Dr. Sal
oni provides is unmatched. She is an absolute angel.
## [2] My dream of motherhood has come true because of her and we are eternally grateful to h
er.
## [3] It was a great experience when we first met Dr. Datar. My wife was little tense to vis
it a male gynecologist but after his understanding to the patient and accurate consultation w
ith a big smile, make it easy for a pregnant woman. From day 1 to delivery, he guided my wife
very well and give a strong mental support for her problems during pregnancy. He encouraged h
er to give natural birth and never pushed us for c- section even we touched our due date for
delivery.
## [4] In his consultation, today we are blessed with a baby girl with normal delivery and my
wife has no complications.
## [5] Thanks to Dr. Nikhil Datar to give us always a positive guidance and consultation to m
ake our 9 months journey safer and smoother.

# Cleaning the Data

# Concvert into lowercae

mother.corpus <- tm_map(mother.corpus, tolower)

## Warning in tm_map.SimpleCorpus(mother.corpus, tolower): transformation


## drops documents

inspect(mother.corpus[1:5])

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 3/20


2/7/2020 Final-Project---Knit.utf8.md

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] i went to dr. saloni for a regular check-up before we were planning for a baby and it
turned out to be the best decision of my life. we had a long but fruitful journey with her. b
ecause of all the care and guidance of dr. saloni, we are blessed with a healthy baby girl. i
wasn't a straightforward case to handle, but she managed all my complications like a pro. rig
ht from pre conception to post delivery she has been just amazing. the fact that she is acces
sible over a phone helped me to put all my worries to end. she personally kept track of my pr
ogress and health conditions regularly. the quality of care and level of support that dr. sal
oni provides is unmatched. she is an absolute angel.
## [2] my dream of motherhood has come true because of her and we are eternally grateful to h
er.
## [3] it was a great experience when we first met dr. datar. my wife was little tense to vis
it a male gynecologist but after his understanding to the patient and accurate consultation w
ith a big smile, make it easy for a pregnant woman. from day 1 to delivery, he guided my wife
very well and give a strong mental support for her problems during pregnancy. he encouraged h
er to give natural birth and never pushed us for c- section even we touched our due date for
delivery.
## [4] in his consultation, today we are blessed with a baby girl with normal delivery and my
wife has no complications.
## [5] thanks to dr. nikhil datar to give us always a positive guidance and consultation to m
ake our 9 months journey safer and smoother.

# Remove Numbers

mother.corpus <- tm_map(mother.corpus,removeNumbers)

## Warning in tm_map.SimpleCorpus(mother.corpus, removeNumbers):


## transformation drops documents

inspect(mother.corpus[1:5])

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 4/20


2/7/2020 Final-Project---Knit.utf8.md

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] i went to dr. saloni for a regular check-up before we were planning for a baby and it
turned out to be the best decision of my life. we had a long but fruitful journey with her. b
ecause of all the care and guidance of dr. saloni, we are blessed with a healthy baby girl. i
wasn't a straightforward case to handle, but she managed all my complications like a pro. rig
ht from pre conception to post delivery she has been just amazing. the fact that she is acces
sible over a phone helped me to put all my worries to end. she personally kept track of my pr
ogress and health conditions regularly. the quality of care and level of support that dr. sal
oni provides is unmatched. she is an absolute angel.
## [2] my dream of motherhood has come true because of her and we are eternally grateful to h
er.
## [3] it was a great experience when we first met dr. datar. my wife was little tense to vis
it a male gynecologist but after his understanding to the patient and accurate consultation w
ith a big smile, make it easy for a pregnant woman. from day to delivery, he guided my wife
very well and give a strong mental support for her problems during pregnancy. he encouraged h
er to give natural birth and never pushed us for c- section even we touched our due date for
delivery.
## [4] in his consultation, today we are blessed with a baby girl with normal delivery and my
wife has no complications.
## [5] thanks to dr. nikhil datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother.

# Remove Puntuations

mother.corpus <- tm_map(mother.corpus,removePunctuation)

## Warning in tm_map.SimpleCorpus(mother.corpus, removePunctuation):


## transformation drops documents

inspect(mother.corpus[1:5])

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 5/20


2/7/2020 Final-Project---Knit.utf8.md

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] i went to dr saloni for a regular checkup before we were planning for a baby and it tu
rned out to be the best decision of my life we had a long but fruitful journey with her becau
se of all the care and guidance of dr saloni we are blessed with a healthy baby girl i wasnt
a straightforward case to handle but she managed all my complications like a pro right from p
re conception to post delivery she has been just amazing the fact that she is accessible over
a phone helped me to put all my worries to end she personally kept track of my progress and h
ealth conditions regularly the quality of care and level of support that dr saloni provides i
s unmatched she is an absolute angel
## [2] my dream of motherhood has come true because of her and we are eternally grateful to h
er
## [3] it was a great experience when we first met dr datar my wife was little tense to visit
a male gynecologist but after his understanding to the patient and accurate consultation with
a big smile make it easy for a pregnant woman from day to delivery he guided my wife very we
ll and give a strong mental support for her problems during pregnancy he encouraged her to gi
ve natural birth and never pushed us for c section even we touched our due date for delivery
## [4] in his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications
## [5] thanks to dr nikhil datar to give us always a positive guidance and consultation to ma
ke our months journey safer and smoother

# Remove Stopwords , first we have to define stopwords

my_stopwords <- c(stopwords('english'),'http.*')


mother.corpus <- tm_map(mother.corpus,removeWords,my_stopwords)

## Warning in tm_map.SimpleCorpus(mother.corpus, removeWords, my_stopwords):


## transformation drops documents

inspect(mother.corpus[1:5])

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] went dr saloni regular checkup planning baby turned best decision lif
e long fruitful journey care guidance dr saloni blessed healthy baby girl wa
snt straightforward case handle managed complications like pro right pre conception
post delivery just amazing fact accessible phone helped put worries end person
ally kept track progress health conditions regularly quality care level support dr sa
loni provides unmatched absolute angel
## [2] dream motherhood come true eternally grateful
## [3] great experience first met dr datar wife little tense visit male gynecologist
understanding patient accurate consultation big smile make easy pregnant woman day
delivery guided wife well give strong mental support problems pregnancy encouraged
give natural birth never pushed us c section even touched due date delivery
## [4] consultation today blessed baby girl normal delivery wife complications
## [5] thanks dr nikhil datar give us always positive guidance consultation make month
s journey safer smoother

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 6/20


2/7/2020 Final-Project---Knit.utf8.md

# Remving the extra whitesppace

mother.corpus <- tm_map(mother.corpus,stripWhitespace)

## Warning in tm_map.SimpleCorpus(mother.corpus, stripWhitespace):


## transformation drops documents

inspect(mother.corpus[1:5])

## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 5
##
## [1] went dr saloni regular checkup planning baby turned best decision life long fruitful
journey care guidance dr saloni blessed healthy baby girl wasnt straightforward case handle m
anaged complications like pro right pre conception post delivery just amazing fact accessible
phone helped put worries end personally kept track progress health conditions regularly quali
ty care level support dr saloni provides unmatched absolute angel
## [2] dream motherhood come true eternally grateful
## [3] great experience first met dr datar wife little tense visit male gynecologist underst
anding patient accurate consultation big smile make easy pregnant woman day delivery guided w
ife well give strong mental support problems pregnancy encouraged give natural birth never pu
shed us c section even touched due date delivery
## [4] consultation today blessed baby girl normal delivery wife complications
## [5] thanks dr nikhil datar give us always positive guidance consultation make months journ
ey safer smoother

#Building Term Document Matrix

mother.dtm <- TermDocumentMatrix(mother.corpus)


dim(mother.dtm)

## [1] 2685 964

inspect(mother.dtm[1:5,1:5])

## <<TermDocumentMatrix (terms: 5, documents: 5)>>


## Non-/sparse entries: 6/19
## Sparsity : 76%
## Maximal term length: 10
## Weighting : term frequency (tf)
## Sample :
## Docs
## Terms 1 2 3 4 5
## absolute 1 0 0 0 0
## accessible 1 0 0 0 0
## amazing 1 0 0 0 0
## angel 1 0 0 0 0
## baby 2 0 0 1 0

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 7/20


2/7/2020 Final-Project---Knit.utf8.md

#convert data into the matrix to store the file

mat= as.matrix(mother.dtm)
write.csv(file='Motherdtm.csv', mat)

# Find the frequency


wordfreq <- data.frame(apply(mother.dtm,1,sum))# if 1, sum will be row wise, and if 2, sum wi
ll be column wise
head(wordfreq)

## apply.mother.dtm..1..sum.
## absolute 4
## accessible 10
## amazing 62
## angel 11
## baby 129
## best 78

wordfreq <- data.frame(ST=row.names(wordfreq), Freq=wordfreq[,1])

#plot of the freq

wordfreq <- wordfreq[order(wordfreq$Freq, decreasing = T),]


wordfreq <- wordfreq[1:10,]

barplot(wordfreq$Freq,name=wordfreq$ST)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 8/20


2/7/2020 Final-Project---Knit.utf8.md

#Basic Text Analysis

findFreqTerms(mother.dtm,70) # no of words coming that many times

## [1] "baby" "best" "care" "delivery" "just"


## [6] "like" "datar" "experience" "first" "great"
## [11] "patient" "pregnancy" "well" "always" "nikhil"
## [16] "positive" "recommend" "will" "doctor" "every"
## [21] "one" "way" "hospital" "time" "thank"
## [26] "everything" "friendly" "feel" "good" "made"
## [31] "really" "also" "happy" "comfortable" "treatment"
## [36] "explained"

findFreqTerms(mother.dtm,100) # no of words coming that many times

## [1] "baby" "delivery" "datar" "experience" "pregnancy"


## [6] "always" "recommend" "will" "doctor" "time"
## [11] "friendly" "good" "also"

# Correlation
findAssocs(mother.dtm,"pregnancy",0.2)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 9/20


2/7/2020 Final-Project---Knit.utf8.md

## $pregnancy
## stay journey ensuring ease questions
## 0.36 0.34 0.33 0.33 0.31
## judged knew specialisation astonishing conerns
## 0.31 0.31 0.31 0.31 0.31
## continued event godmother initial lingering
## 0.31 0.31 0.31 0.31 0.31
## mindset miracle modes moon note
## 0.31 0.31 0.31 0.31 0.31
## peace princess absolutely jovial beautiful
## 0.31 0.31 0.30 0.30 0.29
## colleague ensured experience hear put
## 0.29 0.29 0.28 0.28 0.27
## throughout helping world safe made
## 0.27 0.27 0.27 0.26 0.26
## attend available datar extensive modern
## 0.26 0.25 0.24 0.24 0.24
## connected deep honestly impeccable mind
## 0.24 0.24 0.24 0.24 0.24
## techniques best delivery saloni special
## 0.24 0.23 0.23 0.23 0.23
## relax previous anecdotal checks cherishable
## 0.23 0.23 0.23 0.23 0.23
## faces intervals kiddo kudos midnight
## 0.23 0.23 0.23 0.23 0.23
## paed weirdest able needs silly
## 0.23 0.23 0.23 0.23 0.23
## smallest bring parenthood soul suchak
## 0.23 0.23 0.23 0.23 0.23
## womans smoothly experiences minds sailing
## 0.23 0.23 0.23 0.23 0.23
## tobe diabetes gestational pressure like
## 0.23 0.23 0.23 0.23 0.22
## consultation positive also pleasant dataranything
## 0.22 0.22 0.22 0.22 0.22
## doll package sail first nikhil
## 0.22 0.22 0.22 0.21 0.21
## least hands ended answer needed
## 0.21 0.21 0.21 0.21 0.21
## absolute rock intelligent felt convinced
## 0.20 0.20 0.20 0.20 0.20
## find wants
## 0.20 0.20

findAssocs(mother.dtm,"motherhood",0.4)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 10/20


2/7/2020 Final-Project---Knit.utf8.md

## $motherhood
## dream attain ectopic sooner tadaaaa
## 0.53 0.53 0.53 0.53 0.53
## anxiousbut aspires awaylove birthgiver decked
## 0.53 0.53 0.53 0.53 0.53
## delighted desire faded godbut godhaving
## 0.53 0.53 0.53 0.53 0.53
## listena lowa message morebeing psychological
## 0.53 0.53 0.53 0.53 0.53
## specialdr spirit traitsfor treasurous uplifted
## 0.53 0.53 0.53 0.53 0.53
## used welcome chances paranoid birthday
## 0.53 0.53 0.43 0.43 0.43
## drsaloni thankyou
## 0.43 0.43

#WordCloud
library(wordcloud)

library(RColorBrewer)

display.brewer.all()

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 11/20


2/7/2020 Final-Project---Knit.utf8.md

pal <- brewer.pal(8,"Dark2")

par(bg= "black")

wordcloud(mother.corpus,colors = c("tomato","wheat","lightblue"),scale = c(6,0.5),random.colo


r = TRUE,rot.per = 0.5,min.freq = 60,max.words = 50,font = 2, family = "serif")

## Warning in wordcloud(mother.corpus, colors = c("tomato", "wheat",


## "lightblue"), : friendly could not be fit on page. It will not be plotted.

wordcloud(mother.corpus,colors = pal,scale = c(6,0.5),random.color = TRUE,rot.per = 0.5,min.f


req = 60 ,max.words = 50,font = 2, family = "serif")

#instead of the colors we can use the palate and use any color combination.

mother2 <- data.frame(mother)


head(mother2)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 12/20


2/7/2020 Final-Project---Knit.utf8.md

##
Review
## 1 I went to Dr. Saloni for a regular check-up before we were planning for a baby and it tu
rned out to be the best decision of my life. We had a long but fruitful journey with her. Bec
ause of all the care and guidance of Dr. Saloni, we are blessed with a healthy baby girl. I w
asn't a straightforward case to handle, but she managed all my complications like a pro. Righ
t from pre conception to post delivery she has been just amazing. The fact that she is access
ible over a phone helped me to put all my worries to end. She personally kept track of my pro
gress and health conditions regularly. The quality of care and level of support that Dr. Salo
ni provides is unmatched. She is an absolute angel.
## 2
My dream of motherhood has come true because of her and we are eternally grateful to her.
## 3
It was a great experience when we first met Dr. Datar. My wife was little tense to visit a ma
le gynecologist but after his understanding to the patient and accurate consultation with a b
ig smile, make it easy for a pregnant woman. From day 1 to delivery, he guided my wife very w
ell and give a strong mental support for her problems during pregnancy. He encouraged her to
give natural birth and never pushed us for c- section even we touched our due date for delive
ry.
## 4
In his consultation, today we are blessed with a baby girl with normal delivery and my wife h
as no complications.
## 5
Thanks to Dr. Nikhil Datar to give us always a positive guidance and consultation to make our
9 months journey safer and smoother.
## 6
I will recommend to everyone for any gynaecology issue, plz visit him for your happiness
??????

#Clean the data


mother2 <- gsub("http.*","",mother2$Review) # grab the substring
head(mother2)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 13/20


2/7/2020 Final-Project---Knit.utf8.md

## [1] "I went to Dr. Saloni for a regular check-up before we were planning for a baby and it
turned out to be the best decision of my life. We had a long but fruitful journey with her. B
ecause of all the care and guidance of Dr. Saloni, we are blessed with a healthy baby girl. I
wasn't a straightforward case to handle, but she managed all my complications like a pro. Rig
ht from pre conception to post delivery she has been just amazing. The fact that she is acces
sible over a phone helped me to put all my worries to end. She personally kept track of my pr
ogress and health conditions regularly. The quality of care and level of support that Dr. Sal
oni provides is unmatched. She is an absolute angel."
## [2] "My dream of motherhood has come true because of her and we are eternally grateful to
her."
## [3] "It was a great experience when we first met Dr. Datar. My wife was little tense to vi
sit a male gynecologist but after his understanding to the patient and accurate consultation
with a big smile, make it easy for a pregnant woman. From day 1 to delivery, he guided my wif
e very well and give a strong mental support for her problems during pregnancy. He encouraged
her to give natural birth and never pushed us for c- section even we touched our due date for
delivery."
## [4] "In his consultation, today we are blessed with a baby girl with normal delivery and m
y wife has no complications."
## [5] "Thanks to Dr. Nikhil Datar to give us always a positive guidance and consultation to
make our 9 months journey safer and smoother."
## [6] "I will recommend to everyone for any gynaecology issue, plz visit him for your happin
ess ??????"

# Remove Hashtag
mother2 <- gsub("#\\w+","",mother2)
mother2 <- gsub("@\\w+","",mother2)
mother2 <- gsub("!\\w+","",mother2)
head(mother2)

## [1] "I went to Dr. Saloni for a regular check-up before we were planning for a baby and it
turned out to be the best decision of my life. We had a long but fruitful journey with her. B
ecause of all the care and guidance of Dr. Saloni, we are blessed with a healthy baby girl. I
wasn't a straightforward case to handle, but she managed all my complications like a pro. Rig
ht from pre conception to post delivery she has been just amazing. The fact that she is acces
sible over a phone helped me to put all my worries to end. She personally kept track of my pr
ogress and health conditions regularly. The quality of care and level of support that Dr. Sal
oni provides is unmatched. She is an absolute angel."
## [2] "My dream of motherhood has come true because of her and we are eternally grateful to
her."
## [3] "It was a great experience when we first met Dr. Datar. My wife was little tense to vi
sit a male gynecologist but after his understanding to the patient and accurate consultation
with a big smile, make it easy for a pregnant woman. From day 1 to delivery, he guided my wif
e very well and give a strong mental support for her problems during pregnancy. He encouraged
her to give natural birth and never pushed us for c- section even we touched our due date for
delivery."
## [4] "In his consultation, today we are blessed with a baby girl with normal delivery and m
y wife has no complications."
## [5] "Thanks to Dr. Nikhil Datar to give us always a positive guidance and consultation to
make our 9 months journey safer and smoother."
## [6] "I will recommend to everyone for any gynaecology issue, plz visit him for your happin
ess ??????"

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 14/20


2/7/2020 Final-Project---Knit.utf8.md

#Remove numbers & other languages


mother2 <- gsub("[^A-Z a-z///]","",mother2)# remove non english languages if u wnat numbers w
rite 0-9 after a-z
head(mother2)

## [1] "I went to Dr Saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life We had a long but fruitful journey with her Beca
use of all the care and guidance of Dr Saloni we are blessed with a healthy baby girl I wasnt
a straightforward case to handle but she managed all my complications like a pro Right from p
re conception to post delivery she has been just amazing The fact that she is accessible over
a phone helped me to put all my worries to end She personally kept track of my progress and h
ealth conditions regularly The quality of care and level of support that Dr Saloni provides i
s unmatched She is an absolute angel"
## [2] "My dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "It was a great experience when we first met Dr Datar My wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman From day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy He encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "In his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "Thanks to Dr Nikhil Datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "I will recommend to everyone for any gynaecology issue plz visit him for your happine
ss "

#Remove Whitespace
mother2 <- trimws(gsub("\\s+"," ",mother2))# there should be space in betwwen thw inverted co
mmma, otherwise the data
head(mother2)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 15/20


2/7/2020 Final-Project---Knit.utf8.md

## [1] "I went to Dr Saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life We had a long but fruitful journey with her Beca
use of all the care and guidance of Dr Saloni we are blessed with a healthy baby girl I wasnt
a straightforward case to handle but she managed all my complications like a pro Right from p
re conception to post delivery she has been just amazing The fact that she is accessible over
a phone helped me to put all my worries to end She personally kept track of my progress and h
ealth conditions regularly The quality of care and level of support that Dr Saloni provides i
s unmatched She is an absolute angel"
## [2] "My dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "It was a great experience when we first met Dr Datar My wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman From day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy He encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "In his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "Thanks to Dr Nikhil Datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "I will recommend to everyone for any gynaecology issue plz visit him for your happine
ss"

#Unique tweets to be there


mother2 <- unique(mother2)
head(mother2)

## [1] "I went to Dr Saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life We had a long but fruitful journey with her Beca
use of all the care and guidance of Dr Saloni we are blessed with a healthy baby girl I wasnt
a straightforward case to handle but she managed all my complications like a pro Right from p
re conception to post delivery she has been just amazing The fact that she is accessible over
a phone helped me to put all my worries to end She personally kept track of my progress and h
ealth conditions regularly The quality of care and level of support that Dr Saloni provides i
s unmatched She is an absolute angel"
## [2] "My dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "It was a great experience when we first met Dr Datar My wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman From day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy He encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "In his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "Thanks to Dr Nikhil Datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "I will recommend to everyone for any gynaecology issue plz visit him for your happine
ss"

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 16/20


2/7/2020 Final-Project---Knit.utf8.md

#To lower
mother2 <- tolower(mother2)
head(mother2)

## [1] "i went to dr saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life we had a long but fruitful journey with her beca
use of all the care and guidance of dr saloni we are blessed with a healthy baby girl i wasnt
a straightforward case to handle but she managed all my complications like a pro right from p
re conception to post delivery she has been just amazing the fact that she is accessible over
a phone helped me to put all my worries to end she personally kept track of my progress and h
ealth conditions regularly the quality of care and level of support that dr saloni provides i
s unmatched she is an absolute angel"
## [2] "my dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "it was a great experience when we first met dr datar my wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman from day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy he encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "in his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "thanks to dr nikhil datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "i will recommend to everyone for any gynaecology issue plz visit him for your happine
ss"

#To remove all the blank rows


mother2 <- mother2[which(mother2!="")]
head(mother2)

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 17/20


2/7/2020 Final-Project---Knit.utf8.md

## [1] "i went to dr saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life we had a long but fruitful journey with her beca
use of all the care and guidance of dr saloni we are blessed with a healthy baby girl i wasnt
a straightforward case to handle but she managed all my complications like a pro right from p
re conception to post delivery she has been just amazing the fact that she is accessible over
a phone helped me to put all my worries to end she personally kept track of my progress and h
ealth conditions regularly the quality of care and level of support that dr saloni provides i
s unmatched she is an absolute angel"
## [2] "my dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "it was a great experience when we first met dr datar my wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman from day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy he encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "in his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "thanks to dr nikhil datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "i will recommend to everyone for any gynaecology issue plz visit him for your happine
ss"

#To remove only 2 -3 characters


mother2 <- mother2[nchar(mother2)!=3]
head(mother2)

## [1] "i went to dr saloni for a regular checkup before we were planning for a baby and it t
urned out to be the best decision of my life we had a long but fruitful journey with her beca
use of all the care and guidance of dr saloni we are blessed with a healthy baby girl i wasnt
a straightforward case to handle but she managed all my complications like a pro right from p
re conception to post delivery she has been just amazing the fact that she is accessible over
a phone helped me to put all my worries to end she personally kept track of my progress and h
ealth conditions regularly the quality of care and level of support that dr saloni provides i
s unmatched she is an absolute angel"
## [2] "my dream of motherhood has come true because of her and we are eternally grateful to
her"
## [3] "it was a great experience when we first met dr datar my wife was little tense to visi
t a male gynecologist but after his understanding to the patient and accurate consultation wi
th a big smile make it easy for a pregnant woman from day to delivery he guided my wife very
well and give a strong mental support for her problems during pregnancy he encouraged her to
give natural birth and never pushed us for c section even we touched our due date for deliver
y"
## [4] "in his consultation today we are blessed with a baby girl with normal delivery and my
wife has no complications"
## [5] "thanks to dr nikhil datar to give us always a positive guidance and consultation to m
ake our months journey safer and smoother"
## [6] "i will recommend to everyone for any gynaecology issue plz visit him for your happine
ss"

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 18/20


2/7/2020 Final-Project---Knit.utf8.md

#### Get Emotion using NRC #####


word.df <- as.vector(mother2)
emotion.df <- get_nrc_sentiment(word.df)
emotion.df2 <- cbind(mother2,emotion.df)

# sum of the values of all the emotions


score <- data.frame(colSums(emotion.df[,]))
score <- data.frame(ST=row.names(score),Freq=score[,1])

library(ggplot2)

## Warning: package 'ggplot2' was built under R version 3.6.1

##
## Attaching package: 'ggplot2'

## The following object is masked from 'package:NLP':


##
## annotate

p <- ggplot(data = score,aes(x=ST,y=Freq,fill=ST))


p+geom_bar(stat = "identity",position = 'stack')+ ggtitle('Sentimental Analysis')

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 19/20


2/7/2020 Final-Project---Knit.utf8.md

## Get Sentiment ##
sent.value <- get_sentiment(word.df)
head(sent.value)

## [1] 11.85 2.35 8.35 2.20 2.85 1.65

emotion.df2$catg_senti <- ifelse(sent.value < 0, "Negative", ifelse(sent.value > 0, "Positiv


e", "Neutral"))
table(emotion.df2$catg_senti)

##
## Negative Neutral Positive
## 38 22 663

# remove stopwords for wordcloud, or else u will get only stopwords in ur wordcloud

file:///C:/Users/Prashant Gupta/Desktop/Machie Learning/Final-Project---Knit.html 20/20

You might also like