Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
YStrano
GitHub Repository: YStrano/DataScience_GA
Path: blob/master/lessons/lesson_13/practice/sentiment_analysis-lab.ipynb
1904 views
Kernel: Python 2

Airline Tweets Sentiment Analysis Lab

Authors: Phillippa Thomson (NYC)


You are going to be analyzing tweets about airlines. These have been hand-tagged with sentiment. There are three categories: positive, neutral, and negative.

Use VADER to calculate sentiment for each tweet, and see if you can correctly predict the hand-tagged sentiment.

What is the accuracy? Print out a heatmap to see where your model performs well, and where it performs poorly.

import pandas as pd import numpy as np from sklearn.metrics import classification_report, confusion_matrix, accuracy_score, \ precision_score, recall_score import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline
tweets = pd.read_csv("../data/Tweets.csv")
(Output Hidden)
tweets.head()

1. Preview the airline_sentiment column.

  • What percentage of reviews are positive, neutral, and negative?

# A:

2. Load in the Sentiment IntensityAnalyzer from Vader and add compound, negative, neutral, and positive scores into the DataFrame.

# A:
# A:
# A:

3. Store airline_sentiment in y to use as labels and create an appropriate feature matrix, X.

# A:

4. Fit a model of your choice to predict airline_sentient and cross-validate.

# A:
# A:
# A:
# A:

5. Display the confusion matrix.

  • What reviews are difficult to identify?

# A:

6. Print the classification report and discuss the characteristics of the model.

# A:

The model does ok with negative tweets (the predominant class) but quite poorly with neutral.

To put this in perspective, human concordance, the probability that two people assign the same sentiment to an observation is usually around 70%-80% our baseline is at 63%. Even small increases in accuracy quickly move us towards a theoretical maximum in performance.