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 pandas as pd | |
import numpy as np | |
df = pd.read_csv("news_en.csv", sep=',',index_col = "id") | |
print(df.shape) | |
df.head() |
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 gensim | |
def read_corpus(fname, tokens_only=False): | |
for i, line in enumerate(fname): | |
if tokens_only: | |
yield gensim.utils.simple_preprocess(line) | |
else: | |
yield gensim.models.doc2vec.TaggedDocument(gensim.utils.simple_preprocess(line), [i]) | |
train_corpus = list(read_corpus(df_train["Body"])) |
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
allvecs=[] | |
for i in range(len(train_corpus)): | |
allvecs.append(model.docvecs[i]) | |
df_train["vec"] = allvecs |
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 quandl | |
quandl.ApiConfig.api_key = "YOURKEY" | |
apple = quandl.get("EOD/AAPL", start_date="2016-02-22", end_date="2018-07-23") | |
print(apple.shape) | |
apple.head() |
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
apple["Daily Change"] = apple["Adj_Close"].diff(periods=1) | |
apple.head() |
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
result = pd.merge(df_train, apple, on='Date') | |
print(result.shape) |
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 numpy as np | |
feat, y = result["vec"].values, result["Daily Change"].values | |
frames = [pd.DataFrame(result["vec"].values[i]).transpose() for i in range(result.shape[0]) ] | |
X = pd.concat(frames) |
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 keras.models import Sequential | |
from keras.layers import Input, Dense, Dropout | |
from keras.models import Model | |
regmodel = Sequential() | |
regmodel.add(Dense(150, activation='relu', input_shape=(300,))) | |
regmodel.add(Dropout(0.5)) | |
regmodel.add(Dense(75, activation='relu')) | |
regmodel.add(Dropout(0.5)) | |
regmodel.add(Dense(1, activation='linear')) |
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
regmodel.compile(loss='mse', optimizer='adam') | |
history = regmodel.fit(X, y, epochs=500, verbose=2) |
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 scipy.stats.stats import pearsonr | |
ytrain = np.squeeze(regmodel.predict(X)) | |
pearsonr(ytrain, y) |
OlderNewer