Created
November 13, 2019 09:29
-
-
Save joeng03/b213ecc792ee7ba613b7f2a7eb0a6ccf to your computer and use it in GitHub Desktop.
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.preprocessing import MinMaxScaler | |
data = df.sort_index(ascending=True, axis=0) | |
new_data = pd.DataFrame(index=range(0,len(df)),columns=['Date', 'Close']) | |
for i in range(0,len(data)): | |
new_data['Date'][i] = data['Date'][i] | |
new_data['Close'][i] = data['Close'][i] | |
new_data.index = new_data.Date | |
new_data.drop('Date', axis=1, inplace=True) | |
dataset = new_data.values | |
scaler = MinMaxScaler(feature_range=(0, 1)) | |
scaled_data = scaler.fit_transform(dataset) | |
train= scaled_data[:int(df.shape[0]*0.8)] | |
valid = scaled_data[int(df.shape[0]*0.8):] | |
x_train,y_train,x_test,y_test = [],[],[],[] | |
for i in range(60,train.shape[0]): | |
x_train.append(train[i-60:i,0]) | |
y_train.append(train[i,0]) | |
for z in range(60,valid.shape[0]): | |
x_test.append(valid[z-60:z,0]) | |
y_test.append(valid[z,0]) | |
x_train, y_train,x_test,y_test = np.array(x_train), np.array(y_train),np.array(x_test),np.array(y_test) | |
x_train = np.reshape(x_train, (x_train.shape[0],x_train.shape[1],1)) | |
x_test=np.reshape(x_test,(x_test.shape[0],x_test.shape[1],1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment