Classifying tweets in real time

We can use our model in order to classify tweets in real time using Twitter’s API. In order to simplify things, we will make use of a very popular wrapper library for the API, tweepy (https://github.com/tweepy/tweepy). Installation is easily achieved with pip install tweepy. The first step to accessing Twitter programmatically is to generate relevant credentials. This is achieved by navigating to https://apps.twitter.com/ and selecting Create an app. The application process is straightforward and should be accepted quickly.

Using tweepy's StreamListener, we will define a class that listens for incoming tweets, and as soon as they arrive, it classifies them and prints the original text and predicted polarity. ...

Get Hands-On Ensemble Learning with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.