我是使用Keras的新手。已经使用Python修改了代码,并尝试将其与从Yahoo Finance下载的股票价格一起使用。
出于某种原因,我认为代码运行不正常。在运行期间,损失和准确度为零。我怀疑这是因为代码是为二进制输出创建的(因为我直接从Keras网站改编它)。
数据来自here
import pandas as pd
import numpy as np
import os
from keras.models import Sequential
from keras.layers import Dense, Dropout
from sklearn.model_selection import train_test_split
data_original = pd.read_csv('C:/Users/user/Desktop/Work/Test Python/TestTensorflow/Data/0001_HK.csv')
data_length = len(data_original)
x_original = data_original['close']
x = x_original[0:data_length-2]
x1 = x_original[1:data_length-1]
x = np.reshape(x.as_matrix(),(len(x),1))
x1 = np.reshape(x1.as_matrix(),(len(x),1))
x = np.append(x,x1,axis = 1)
y = data_original['close']
y = y[2:data_length]
y = np.reshape(y.as_matrix(),(len(y),1))
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size = 0.3,random_state = 42)
model = Sequential()
model.add(Dense(64, input_dim=2, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error',
optimizer='rmsprop',
metrics=['accuracy'])
model.fit(x_train, y_train,
epochs=20)
score = model.evaluate(x_test, y_test, batch_size=128)
代码的目的只是为了获取2天的价格数据,并用它来预测第二天的价格。
任何人都知道我需要做哪些修改?任何帮助表示赞赏!
答案 0 :(得分:0)
找出问题所在。输入中有错误。案件结案。