Skip to content

Instantly share code, notes, and snippets.

View khuangaf's full-sized avatar
:octocat:
Focusing

Kung-Hsiang Steeve Huang khuangaf

:octocat:
Focusing
View GitHub Profile
@khuangaf
khuangaf / Screenshot
Created March 29, 2016 15:46
Screenshot
#include <cstdlib>
#include <cstddef>
#include <windows.h>
#include <string>
#include <iostream>
#define MOD_NOREPEAT 0x4000
#define MOD_ALT 0x0001
using namespace std;
void shortCut(int argc, TCHAR *argv[]);
@khuangaf
khuangaf / DataCollection
Created January 1, 2018 01:19
CrytocurrencyPrediction
import json
import numpy as np
import os
import pandas as pd
import urllib2
# connect to poloniex's API
url = 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_BTC&start=1356998100&end=9999999999&period=300'
# parse json returned from the API to Pandas DF
@khuangaf
khuangaf / PastSampler
Last active January 1, 2018 01:26
CryptocurrencyPrediction
import numpy as np
import pandas as pd
class PastSampler:
'''
Forms training samples for predicting future values from past value
'''
def __init__(self, N, K, sliding_window = True):
'''
@khuangaf
khuangaf / Sample2h5
Created January 1, 2018 01:29
CryptocurrencyPrediction
file_name='bitcoin2015to2017_close.h5'
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
# normalization
for c in columns:
df[c] = scaler.fit_transform(df[c].values.reshape(-1,1))
#Features are input sample dimensions(channels)
A = np.array(df)[:,None,:]
@khuangaf
khuangaf / CNN
Last active January 1, 2018 01:43
CryptocurrencyPrediction
import pandas as pd
import numpy as numpy
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv1D, MaxPooling1D, LeakyReLU, PReLU
from keras.utils import np_utils
from keras.callbacks import CSVLogger, ModelCheckpoint
import h5py
import os
import tensorflow as tf
@khuangaf
khuangaf / LSTM
Created January 1, 2018 02:02
CyptocurrencyPrediction
import pandas as pd
import numpy as numpy
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten,Reshape
from keras.layers import Conv1D, MaxPooling1D
from keras.utils import np_utils
from keras.layers import LSTM, LeakyReLU
from keras.callbacks import CSVLogger, ModelCheckpoint
import h5py
import os
@khuangaf
khuangaf / GRU
Created January 1, 2018 02:32
CryptocurrencyPrediction
import pandas as pd
import numpy as numpy
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten,Reshape
from keras.layers import Conv1D, MaxPooling1D, LeakyReLU
from keras.utils import np_utils
from keras.layers import GRU,CuDNNGRU
from keras.callbacks import CSVLogger, ModelCheckpoint
import h5py
import os
@khuangaf
khuangaf / PlotCNN_loadweight
Last active January 1, 2018 02:46
Cryptocurrency
from keras import applications
from keras.models import Sequential
from keras.models import Model
from keras.layers import Dropout, Flatten, Dense, Activation
from keras.callbacks import CSVLogger
import tensorflow as tf
from scipy.ndimage import imread
import numpy as np
import random
from keras.layers import LSTM
model.fit(training_datas, training_labels,verbose=1, batch_size=batch_size,validation_data=(validation_datas,validation_labels), epochs = epochs, callbacks=[CSVLogger(output_file_name+'.csv', append=True),ModelCheckpoint('weights/'+output_file_name+'-{epoch:02d}-{val_loss:.5f}.hdf5', monitor='val_loss', verbose=1,mode='min')]
predicted = model.predict(validation_datas)
predicted_inverted = []
for i in range(original_datas.shape[1]):
scaler.fit(original_datas[:,i].reshape(-1,1))
predicted_inverted.append(scaler.inverse_transform(predicted[:,:,i]))
print np.array(predicted_inverted).shape
#get only the close data
ground_true = ground_true[:,:,0].reshape(-1)
ground_true_times = ground_true_times.reshape(-1)