Oh! human sentiments can be analyzed is it ?!!(my first thought
when I heard about this couple of months back J)
So started digging and thought of sharing an end to end view
on how it can be achieved.
First of all, analysis is all about data. To do Sentiment
Analysis, we need data about our ideas, emotions, feelings, likes, dislikes
...etc. So primary source for this data would be social network like Facebook,
Twitter ...etc.
Outcomes of a Sentiment Analysis can be categorized under Polarity and
Subjectivity.
Polarity is about - Negative,
Neutral or Positive
Subjectivity is about - Objective
or Subjective
Below I am going to explain the steps to do Sentiment
Analysis for Polarity derivation using Twitter feed, Python program and OAC (Oracle Analytics Cloud).
Step#1: Get feed from
Twitter using Python
• Login
to twitter link with your credentials https://developer.twitter.com/ and create an application
• Save
the customerkey, customer secret, accesstoken, accesssecret keys available.
Need this tokens to extract the feed.
• Install
python 3 (or any suitable version) and Install pip and tweepy though command
prompt
• Download
get-pip.py file github.com and follow the steps)
• Run
the command "python get-pip.py" through command prompt.
• "Python.exe
-m pip"(to get list of commands)
• "Python.exe
-m pip install tweepy" (command to install tweepy)
• A
bit of coding now in Python J
(Find a simple template code to get data from twitter)
• Run
the script through command prompt as <<python file name>>. Then CSV twitter file
will get downloaded to your desktop. Use that file in OAC to perform
sentimental analysis.
Step#2: Sentiment
Analysis using OAC
As part of OAC, DVCS has inbuilt capabilities to perform
sentiment Analysis on textual data. To invoke sentimental functionality, add
the twitter data set and create a data flow using the data set
In Oracle DV, sentiment analysis is implemented using
Python. To invoke it add Analyze Sentiment node to the dataflow.
§
Click on create Data set and select the twitter
csv file and click on add
§
Click on create data flow
§
select the data set which you added (twitter
excel) and click on Add
§
For e.g. I took the twitter feed of product XXXXX
and performed sentimental analysis on column "Tweet Text"
• Click on + sign and select "Analyze Sentiment"
• In
the Analyze Sentiment pane, Output section, give a column name
to capture the emotion value. Rename the default column 'emotion' as needed.
• In
the Parameters section, choose the column with text content to analyze
• Click
on select column and add the column from available data for e.g. Tweet Text
• After
adding the analyze sentiment column we can see column with name as emotion and
it indicates the "Positive"," Negative" or "Neutral"
• To
add the column, click on Add step (+) and select the Add Columns
• Rename
the column as required
• Give
the Expression and click on Validate and select apply
• Now
we can see the Count column added to the available data, click on save
• Go
to Home page and click on create and select the Project as shown
• Select
the Dataflow which you created above and click on Add to project
• Select
the attribute emotion and select the count measure and click on pick
visualization (or you can drag drop the columns on right side pane accordingly)
• Below
is the pie chart which is showing the positive, negative or neutral tweets as
per the data available in the data set.
Python Code:
Using the below code snippet you could write a simple code to extract feed from twitter