This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.neural_network import MLPRegressor | |
from nltk.stem.lancaster import LancasterStemmer | |
from nltk.corpus import stopwords | |
import re | |
from operator import itemgetter | |
def prepareSentence(s): | |
stemmer = LancasterStemmer() | |
ignore_words = set(stopwords.words('english')) | |
regpattern = re.compile('[\W_]+" "') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import json | |
import datetime | |
import time | |
# API access details - get yours from Twitter | |
access_token = "********************" | |
access_token_secret = "********************" | |
consumer_key = "********************" | |
consumer_secret = "********************" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import pathlib | |
import os | |
import json | |
#Make sure we're in the same dir that has the downloaded JSON twitter data | |
os.chdir('/home/username/twitter_data') | |
tweets = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = [] | |
for tweet in tweets: | |
words.extend(prepareSentence(tweet["text"])) | |
distinct_words = set(words) | |
lower_threshold = 10 | |
upper_threshold = 350 | |
counts = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toBOW(sentance, words): | |
bag = [] | |
for word in words: | |
bag.append(1) if word in sentance else bag.append(0) | |
return bag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs = [] | |
outputs = [] | |
for tweet in tweets: | |
sentence = prepareSentence(tweet["text"]) | |
# create our bag of words array | |
bag = toBOW(sentence, final_words) | |
inputs.append(bag) | |
#Calculate a score, 1 if any engagement, 0 if none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import feedparser | |
potential_posts = {} | |
for url in ['https://feeds.feedburner.com/CoinDesk', 'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml','http://i.perezhilton.com/?feed=rss2']: | |
feed = feedparser.parse(url) | |
for article in feed.entries: | |
sentence = prepareSentence(article.title) | |
bag = toBOW(sentence, final_words) | |
potential_posts[article.title] = nnet.predict([bag])[0] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import argparse | |
import fnmatch | |
import logging | |
import papermill as pm | |
from datetime import datetime | |
import time | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer