"""
Created on Thu Jul 20 09:59:50 2017
@author: Administrator
"""
import pandas as pd
inputfile = 'input.xlsx'
outputfile = 'output.xls'
modelfile = 'modelweight.model'
data = pd.read_excel(inputfile,index='Date',sheetname=0)
feature = ['F1','F2','F3','F4']
label = ['L1']
data_train = data.loc[range(0,20)].copy()
data_mean = data_train.mean()
data_std = data_train.std()
data_train = (data_train - data_mean)/data_std
x_train = data_train[feature].as_matrix()
y_train = data_train[label].as_matrix()
from keras.optimizers import SGD,adam
from keras.models import Sequential
from keras.layers.core import Dense, Activation
model = Sequential()
model.add(Dense(12,input_dim=4,init='uniform'))
model.add(Activation('relu'))
model.add(Dense(1,input_dim=12))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x_train, y_train, nb_epoch = 1000, batch_size = 6)
model.save_weights(modelfile)
x = ((data[feature] - data_mean[feature])/data_std[feature]).as_matrix()
data[u'L1_pred'] = model.predict(x) * data_std['L1'] + data_mean['L1']
data.to_excel(outputfile)
import matplotlib.pyplot as plt
p = data[['L1','L1_pred']].plot(subplots = True, style=['b-o','r-*'])
plt.show()