</style>
Carson J. Q. Farmer
@carsonfarmer
carsonfarmer.com
carsonfarmer@gmail.com
github.com/cfarmer
Hunter College, City University of New York
695 Park Ave, New York, NY, 10065
Source: Digiself
Traditionally, this type of analysis would require a large investment in heavy-duty computing infrastructure, however, we suggest that a focus on real-time analytics in a lightweight streaming framework is the most logical step forward.
Source: Digiself
Using online Latent Semantic Analysis (LSA) from the gensim Python package, we extract 'topics' from tweets in an online training fashion. To maintain real-time relevance, the topic model is continually updated, and depending on parameterization, can 'forget' past topics. Based on a set of learned topics, a grid of spatially located tweets for each identified topic is generated using standard numpy and scipy.spatial functionality. Using an efficient streaming algorithm for approximating 2D kernel density estimation (KDE), locations with the highest density of tweets on a particular topic are located.
import tweepy
import simplejson
import sys
consumer_key = ''
consumer_secret = ''
access_token_key = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
BOUNDING_BOX = [xmin, ymin, xmax, ymax]
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, tweet):
print('Ran on_status')
def on_error(self, status_code):
print('Error: ' + repr(status_code))
return True # Don't die!
def on_data(self, data):
document = simplejson.loads(data)
# Do something awesome with the tweet info...
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(locations=BOUNDING_BOX)
ark-twokenize-py
), remove common and unique words (stopwords.py
)scipy.stats.kde.gaussian_kde
for large (>1e7
) numbers of pointsPico
- very small web application framework for Python
Python
and client side Javascript
Pico
is a server, a Python
libary and a Javascript
library!Pico
allows you to stream data from Python
to Javascript
Python
generator!# example.py
import pico
def hello(name="World"):
return "Hello " + name
python -m pico.server
<!DOCTYPE HTML>
<html>
<head>
<title>Pico Example</title>
<script src="/pico/client.js"></script>
<script>
pico.load("example");
</script>
</head>
<body>
<p id="message"></p>
<script>
example.hello("Fergal", function(response){
document.getElementById('message').innerHTML = response;
});
</script>
</body>
</html>
import pico
import gevent
@pico.stream
def stream():
for line in open('long_file.txt'):
yield line
gevent.sleep(0.1)
(Plus some other gevent
magic)
example.stream(function(line){
console.log(line)
})
pico
author) just got a 'real-job' and got marriedanaconda
or similar on a server and this will worki'm
, my
, me
, etc…Carson J. Q. Farmer
@carsonfarmer
carsonfarmer.com
carsonfarmer@gmail.com
github.com/cfarmer
Hunter College, City University of New York
695 Park Ave, New York, NY, 10065