\n \n <\/td>\n | #----------------- FEATURE ENGINEERING ------------------------#<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | #---------- Sentiment Score with Vader -----------------#<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | # Instantiate Vader <\/td>\n <\/tr>\n |
\n <\/td>\n | analyser = SentimentIntensityAnalyzer()<\/td>\n <\/tr>\n |
\n <\/td>\n | \n<\/td>\n <\/tr>\n |
\n <\/td>\n | def polarity_scores_all(tweet):<\/td>\n <\/tr>\n |
\n <\/td>\n | '''<\/td>\n <\/tr>\n |
\n <\/td>\n | Takes string of text to:<\/td>\n <\/tr>\n |
\n <\/td>\n | 1. Gets sentiment metrics<\/td>\n <\/tr>\n |
\n <\/td>\n | 2. Returns negative, neutral, positive <\/td>\n <\/tr>\n |
\n <\/td>\n | and compound scores as lists.<\/td>\n <\/tr>\n |
\n <\/td>\n | '''<\/td>\n <\/tr>\n |
\n <\/td>\n | neg, neu, pos, compound = [], [], [], []<\/td>\n <\/tr>\n |
\n <\/td>\n | analyser = SentimentIntensityAnalyzer()<\/td>\n <\/tr>\n |
\n <\/td>\n | <\/td>\n <\/tr>\n |
\n <\/td>\n | for text in tweet:<\/td>\n <\/tr>\n |
\n <\/td>\n | dict_ = analyser.polarity_scores(text)<\/td>\n <\/tr>\n |
\n <\/td>\n | neg.append(dict_['neg'])<\/td>\n <\/tr>\n |
\n <\/td>\n | neu.append(dict_['neu'])<\/td>\n <\/tr>\n |
\n <\/td>\n | pos.append(dict_['pos'])<\/td>\n <\/tr>\n |
\n <\/td>\n | compound.append(dict_['compound'])<\/td>\n <\/tr>\n |
\n <\/td>\n | <\/td>\n <\/tr>\n |
\n <\/td>\n | return neg, neu, pos, compound <\/td>\n <\/tr>\n |
\n <\/td>\n | <\/td>\n <\/tr>\n |
\n <\/td>\n | # Append to your dataset<\/td>\n <\/tr>\n |
\n <\/td>\n | <\/td>\n <\/tr>\n |
\n <\/td>\n | all_scores = polarity_scores_all(train.tidy_tweet.values)<\/td>\n <\/tr>\n |
\n <\/td>\n | train['neg_scores'] = all_scores[0]<\/td>\n <\/tr>\n |
\n <\/td>\n | train['neu_scores'] = all_scores[1]<\/td>\n <\/tr>\n |
\n <\/td>\n | train['pos_scores'] = all_scores[2]<\/td>\n <\/tr>\n |
\n <\/td>\n | train['compound_scores'] = all_scores[3]<\/td>\n <\/tr>\n <\/table>\n<\/div>\n\n\n <\/div>\n\n <\/div>\n<\/div>\n\n <\/div>\n |