Raspberry Pi Twitter Sentiment Analysis Server – Part 1

One of the most read blog posts I’ve done was “Twitter sentiment analysis in 30 seconds” and it’s still one of the most used search terms.

“Imperfection is beauty, madness is genius and it’s better to be absolutely ridiculous than absolutely boring.”

There was a reason I named the blog after a Marilyn Monroe quote, software and data are never perfect. It’s an imperfect medium. The curious nature of developers means that folk will think of you as mad from time to time, that’s okay with me.

So, I have a Raspberry Pi with the standard Raspian Wheezy distro on it. Now I’ve been pondering a dozen ideas but this seems a fun one to do for the sake of the blog, kudos and general mucking around. It is better to be ridiculous than boring….

photo

Assuming you have the basic OS installed and a connection to the internet. I wired my direct to my MacBook Pro with a standard ethernet cable then I can ssh in from the terminal.

The Aim

First things first I want R to use the Twitter library to pull in the results of a Twitter search.  Using a modified version of the sentiment analysis R script then figure out whether a tweet is positive or negative in sentiment.

Another requirement is to store the most recent tweet ID somewhere so on the next run we only pick up tweets from that point onwards.  We’ll use cron to schedule R to run the script on a regular basis.

So, in this part we’ll just get the basics of everything installed.

Installation

There’s a few bits we need to install before we think about the Twitter library.

You’ll need libcurl4-gnutls-dev and libcurl4-openssl-dev installed as R/Twitter library require RCurl and ROauth to be installed.

So from the command line:

sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libcurl4-openssl-dev

Next we install R itself, we only need the base install.

sudo apt-get install r-base-core

Now we can open R and install the Twitter library.

From the command line:

R

This will then give us the R shell.

>install.packages("twitteR", dependencies=TRUE)

This will install the package to read Twitter stuff.  This may take some time as it will download all the required packages and install them too.  You’ll know when you’re done when you see something along the lines of:

* DONE (twitteR)
The downloaded source packages are in
 ‘/tmp/RtmpHYYPNF/downloaded_packages’

To load the library type the following:

> library(twitteR)

This will load in the required libraries ready for use.

Loading required package: ROAuth
Loading required package: RCurl
Loading required package: bitops
Loading required package: digest
Loading required package: rjson

Now since the original blog post the Twitter library now follows Twitter’s API 1.1 which means that most requests will need OAuth authentication.  So that’s the next job but I’m saving that for the next part of the series.

About these ads
Posted in Raspberry Pi, Sentiment Analysis, Twitter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 849 other followers

%d bloggers like this: