text: __author__ = "Luke Liu"
  #encoding="utf-8"
  from keras.layers import Input, Dense, LSTM
  from keras.models import Model
  import  pandas as pd
  import os
  import matplotlib.pyplot as plt
  from sklearn.preprocessing import  MinMaxScaler
  import numpy as np
  import time
  path='D:/BaiduYunDownload/python_exe/dataset/data_stocks.csv'
  data=pd.read_csv(path)
  # 看主要的行信息
  # plt.plot(data['SP500'])
  # plt.show()
  #SP500是大盘走向
  #2017 -09-01 到2017 04-03
  # 去掉了data这一行
  #训练集测试集4:1分配
  # 删除列
  data.drop('DATE', axis=1, inplace=True)
  data_train = data.iloc[:int(data.shape[0] * 0.8), :]
  data_test = data.iloc[int(data.shape[0] * 0.8):, :]
  print(data_train.shape, data_test.shape)
  
  # 数据归一化（-1,1）
  
  scaler = MinMaxScaler(feature_range=(-1, 1))
  scaler.fit(data_train)
  data_train = scaler.transform(data_train)
  data_test = scaler.transform(data_test)
  
  
  
  X_train = data_train[:, 1:]
  y_train = data_train[:, 0]
  X_test = data_test[:, 1:]
  y_test = data_test[:, 0]
  
  output_dim = 1
  batch_size = 256
  epochs = 10
  seq_len = 5
  hidden_size = 128
  
  X_train = np.array([data_train[i : i + seq_len, 0] for i in range(data_train.shape[0] - seq_len)])[:, :, np.newaxis]
  y_train = np.array([data_train[i + seq_len, 0] for i in range(data_train.shape[0] - seq_len)])
  X_test = np.array([data_test[i : i + seq_len, 0] for i in range(data_test.shape[0] - seq_len)])[:, :, np.newaxis]
  y_test = np.array([data_test[i + seq_len, 0] for i in range(data_test.shape[0] - seq_len)])
  
  print(X_train.shape, y_train.shape, X_test.shape, y_test.shape)
  
  X = Input(shape=[X_train.shape[1], X_train.shape[2],])
  h = LSTM(hidden_size, activation='relu')(X)
  Y = Dense(output_dim, activation='sigmoid')(h)
  
  model = Model(X, Y)
  model.compile(loss='mean_squared_error', optimizer='adam')
  model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, shuffle=False)
  y_pred = model.predict(X_test)
  print('MSE Train:', model.evaluate(X_train, y_train, batch_size=batch_size))
  print('MSE Test:', model.evaluate(X_test, y_test, batch_size=batch_size))
  plt.plot(y_test, label='test')
  plt.plot(y_pred, label='pred')
  plt.legend()
  plt.show()