The classifier used in the application.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 24 commits behind corynissen:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


The classifier used in the application.

##Prediction The prediction is done via a webservice running on an EC2 instance running ubuntu, R, apache, and the [FastRWeb package] ( to pull it all together.

###How it's Served The FastRWeb package takes a .R file (fp_classifier.R in my case) with a "run" function and makes it available via the web. I use this to submit text and return a classification...

###Classifier Code I've tried several packages. [RTextTools] ( is a great resource, but a very simple n-gram based system [TextCat] ( is sufficient for this project. It reads in a pre-trained model file on startup, and calculates a predicted classification based on the text input from the user.

##Model Training First, I download the data from our mongodb where it's stored. Then I manually classify the data to train the model. Then save the trained model to a file for use on the server.

###Get the Data First, I download the tweets from mongodb using [RMongo] ( package. Save these tweets to a csv file for the manual classification step.

###Manually Classify I couldn't concentrate well staring at a wall of text, so I found a nugget of code online that allowed me to run a script from the command line and input a single character and not have to hit enter. Basically, I can just keep my fingers on 1 and 0 and rapid fire the manual part of this.

###Train Model The first part is to pre-process the data before training the model. In this case, I take out special characters and punctuation. I also replace all links with "urlextracted". The idea behind this is that nearly all tweets with links in them are "junk", that is, news articles about food poisoning, not specific instances of an illness. So, by treating all of those links the same, the model should associate "urlextracted" with junk fairly well. Then save the trained model as a file.

##R Packages [textcat] ( [stringr] ( [RMongo] ( [FastRWeb] (


Copyright (c) 2013 Cory Nissen. Released under the MIT License.