Skip to content

Instantly share code, notes, and snippets.

View HeshamMeneisi's full-sized avatar
🏠
Working from home

Hesham Meneisi HeshamMeneisi

🏠
Working from home
View GitHub Profile
def series_to_supervised(df, n_in=1, n_out=1, targets=[], dropnan=True):
"""
Converts a time series Pandas DataFrame into a supervised learning problem
returns: X(t-n_in+1,...,t), y(t+1,....,t+n_out)
"""
assert n_in > 0 and n_out > 0
assert all([t in df.columns for t in targets])
n_vars = len(df.columns)
word_list = [doc.words for doc in docs]
bigram = gensim.models.Phrases(word_list)
bigram_phr = gensim.models.phrases.Phraser(bigram)
bi_docs = []
for doc in docs:
words = bigram_phr[doc.words]
tags = doc.tags
from gensim.models import Doc2Vec
import pickle
with open('./docs_proc.pkl', 'rb') as file:
docs = pickle.load(file)
model = Doc2Vec(docs, vector_size = 500, window = 9, min_count = 20, workers=8, dm=0)
with open('./d2v_model.pkl', 'wb') as file:
pickle.dump(model, file)
@HeshamMeneisi
HeshamMeneisi / test_keras.py
Created February 15, 2018 13:08
Testing Keras/TensorFlow/Theano environment.
import numpy as np
import time
import sys
print("## Checking Keras\n\n")
import keras.backend as K
backend = K.backend()
vlen = 10 * 30 * 768
iters = 1000
@HeshamMeneisi
HeshamMeneisi / test_gym.py
Last active February 15, 2018 13:09
Testing OpenAI's Gym
import gym
import time
from gym import envs
print(envs.registry.all())
env = gym.make('CartPole-v0')
env.reset()
t = 0