Created
January 30, 2018 17:18
-
-
Save llSourcell/7494caca6ff7c59585ee628f23ce083c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 praw | |
| import coindesk | |
| import dict_list | |
| import pandas as pd | |
| import word2vec as w2v | |
| #Step 1 - Retrieve Tweets past 30 days | |
| twitter_config = json.load(TWEEPY_CONFIG_FILE) | |
| auth = tweepy.OAuthHandler(**twitter_config) | |
| api = tweepy.API(auth) | |
| public_tweets = api.search('bitcoin') | |
| #Step 2 - Retrieve reddit posts past 30 days | |
| reddit_config = json.load(open(PRAW_CONFIG_FILE)) | |
| reddit = praw.Reddit(**reddit_config) | |
| top_posts = reddit.subreddit('bitcoin').top() | |
| #Step 3 - Retrieve bitcoin data past 30 days | |
| price_list = coindesk.prices('1-1-2017', '30-1-2017') | |
| for i in enumerate(price_list): | |
| if price_list[i] < price_list[i+1] # did the price increase or decrease? | |
| price_list[i] = 0 | |
| else | |
| price_list[i] = 1 | |
| #Step 4 Clean data | |
| input_data = public_tweets + top_posts | |
| final_data | |
| for i in input_data | |
| for x in dict_list | |
| if input_data[i] = dict_list[x] | |
| final_data = input_data[i] | |
| #Step 5 Vectorize Data | |
| vectorized_data = w2v(final_data) | |
| #Step 6 Build LSTM Network model | |
| model = Sequential() | |
| model.add(LSTM(100, input_shape=(trainX.shape[1], trainX.shape[2]))) | |
| model.add(Dense(1)) | |
| model.compile(loss='mae', optimizer='adam') | |
| trained_model = model.fit(vectorized_data, price_list, epochs=300, batch_size=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment