Bitcoin Reddit Classifier

status: frozen
tags: crypto, machine learning

Bitcoin Reddit Classifier a very basic NaiveBayes classifier, based on Reddit posts of a specific keyword for the last 24 hours, trending about Bitcoin.

Running screenshot:



from __future__ import print_function
from __future__ import division
import praw
import sys
from textblob import TextBlob
import nltk
import os
import requests, json
from textblob.classifiers import NaiveBayesClassifier
from colorama import Fore, Back, Style

CLIENT_ID = '*************'
CLIENT_SECRET = '****************'
USERAGENT = 'Someone'
USERNAME = '''punkt')'averaged_perceptron_tagger')'brown')

reddit = praw.Reddit(client_id=CLIENT_ID,

train = [
    ('Bitcoin has increased', 'pos'),
    ('I love bitcoin ', 'pos'),
    ('let\'s go bitcoin!!', 'pos'),
    ('Cryptocurrency market could hit $1 trillion this year with bitcoin surging to $50,000, experts say', 'pos'),
    ('More Bitcoin ATMs Are Being Installed Than Bank ATMs', 'pos'),
    ('bitcoin drops below $8,000 again', 'neg'),
    ('Bitcoin\'s price drops', 'neg'),
    ('Bitcoin went down', 'neg'),
    ('Bitcoin is dead...again...', 'neg'),
    ('Everyone is all worried about the price of bitcoin', 'neg'),
    ('Bitcoin buyer loses $440,000 in matter of weeks after sudden collapse', 'neg'),
    ('Bank for International Settlements says Bitcoin is a pyramid scheme', 'neg'),
    ('Sold all of my remaining BTC', 'neg'),
    ('Bitcoin is rising again', 'pos'),
    ('bans bitcoin', 'neg'),
    ('stopped accepting bitcoin', 'neg'),
    ('Finally investing in Bitcoin!', 'pos'),
    ('no longer accepting bitcoin', 'neg'),
    ('US Olympic Luge Team Welcomes Bitcoin Donations', 'pos'),
    ('European bankers scoff at bitcoin for its risk', 'neg'),
    ('Cryptocurrency Stolen', 'neg'),
    ('Have started accepting Bitcoin as a payment', 'pos'),
    ('bitcoin price is rising', 'pos'),
    ('Bitcoin will replace Traditional Banking', 'pos')

cl = NaiveBayesClassifier(train)
term = sys.argv[1]

print("Searching for %s" %term)

titles = {}

all = reddit.subreddit("all")
for i in, time_filter='day', limit=1000):
    titles[i] = i.title

print("[-] Training model...")
print("[-] Accuracy: %f" %(cl.accuracy(train)))
print("[-] Getting titles...")

global pos, neg
pos = 0
neg = 0

for k,v in titles.items():
    blob = TextBlob(v)
    csf = cl.classify(v)
    if csf == 'pos':
        pos += 1
        print(Fore.GREEN + '+', end='')
        neg += 1
        print(Fore.RED + '-', end='')

def getBitcoinPrice():
    URL = ''
        r = requests.get(URL)
        priceFloat = float(json.loads(r.text)['last'])
        return priceFloat
    except requests.ConnectionError:
        print("Error querying Bitstamp API")

pos_per = (pos/neg)*100
neg_per = 100 - pos_per

print("\n" + '-'*60)
print("Bitcoin last price: $" + str(getBitcoinPrice()) + "/BTC")
print("Total: \n%i positive [%4.1f] \n%i negative [%4.1f]" %(pos, pos_per, neg, neg_per))
print("\n" + '-'*60)