我正在尝试对数据进行拟合/训练以使其具有一定的前提条件,但是当我将file.csv更改为自己的数据集时,这是行不通的,假设lesson_test和我的数据具有相同的范围列和类型(日期除外)。 (Neural Network to Predict Stock Markets)。
我试图看看发生了什么,我发现我的训练和测试变量与实际值相差太远了。
# fix random seed for reproducibility
np.random.seed(1)
# load the dataset
df.drop(columns=['High', 'Low', 'Close', 'Volume', 'Adj Close'], inplace = True)
data = df.values
data = data.astype('float32')
# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(data)
# split into train and test sets
train = dataset[0:int(np.around(len(data)*0.7)), :]
test = dataset[int(np.around(len(data)*0.7)):, :]
# reshape into X=t and Y=t+1
lags = 3
X_train, y_train = prepare_data(train, lags)
X_test, y_test = prepare_data(test, lags)
# reshape input to be [samples, time steps, features]
X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
# create and fit the LSTM network
mdl = Sequential()
mdl.add(LSTM(300, activation='softmax', recurrent_activation='relu', input_shape=(1, lags)))
mdl.add(Dense(1, activation='linear'))
mdl.compile(loss='mean_squared_error', optimizer='adam')
history = mdl.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=33, batch_size=100, verbose=2)
# make predictions
train_predict = mdl.predict(X_train)
test_predict = mdl.predict(X_test)
# invert transformation
train_predict = scaler.inverse_transform(train_predict)
y_train = scaler.inverse_transform([y_train])
test_predict = scaler.inverse_transform(test_predict)
y_test = scaler.inverse_transform([y_test])
train_predict
# calculate root mean squared error
train_score = math.sqrt(mean_squared_error(y_train[0], train_predict[:,0]))
print('Train Score: {:.2f} RMSE'.format(train_score))
test_score = math.sqrt(mean_squared_error(y_test[0], test_predict[:,0]))
print('Test Score: {:.2f} RMSE'.format(test_score))
这是我的数据集(问题在这里):
Date,Open,High,Low,Close,Adj Close,Volume
09:00,3851.50,3853.00,3849.50,3850.00,3.851.00,3776
09:01,3850.50,3851.00,3844.50,3846.50,3.848.13,8664
09:02,3846.50,3847.50,3839.00,3841.50,3.843.63,7520
09:03,3841.50,3842.00,3836.50,3840.50,3.840.13,10174
09:04,3840.00,3842.00,3837.00,3837.00,3.839.00,4649
09:05,3837.50,3841.00,3837.00,3837.50,3.838.25,5225
这是课程数据集:
Date,Open,High,Low,Close,Adj Close,Volume
2005/09/27,21.049999,21.400000,19.100000,19.299999,18.588539,961200
2005/09/28,19.299999,20.530001,19.200001,20.500000,19.744297,5747900
2005/09/29,20.400000,20.580000,20.100000,20.209999,19.464989,1078200
2005/09/30,20.260000,21.049999,20.180000,21.010000,20.235500,3123300
2005/10/03,20.900000,21.750000,20.900000,21.500000,20.707432,1057900
2005/10/04,21.440001,22.500000,21.440001,22.160000,21.343109,1768800
你们能帮我吗?
预先感谢
达蒂巴里