gpt4 book ai didi

python - 使用 tflearn python 将数据输入 lstm

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:56 32 4
gpt4 key购买 nike

我知道这方面已经有一些问题,但我找不到问题的答案。我有一个用于回归问题的 LSTM(带有 tflearn)。无论我进行何种修改,我都会遇到 3 种类型的错误。

import pandas
import tflearn
import tensorflow as tf
from sklearn.cross_validation import train_test_split


csv = pandas.read_csv('something.csv', sep = ',')

X_train, X_test = train_test_split(csv.loc[:,['x1', 'x2',
'x3','x4','x5','x6',
'x7','x8','x9',
'x10']].as_matrix())
Y_train, Y_test = train_test_split(csv.loc[:,['y']].as_matrix())

#create LSTM
g = tflearn.input_data(shape=[None, 1, 10])
g = tflearn.lstm(g, 512, return_seq = True)
g = tflearn.dropout(g, 0.5)
g = tflearn.lstm(g, 512)
g = tflearn.dropout(g, 0.5)
g = tflearn.fully_connected(g, 1, activation='softmax')
g = tflearn.regression(g, optimizer='adam', loss = 'mean_square',
learning_rate=0.001)

model = tflearn.DNN(g)
model.fit(X_train, Y_train, validation_set = (Y_train, Y_test))

n_examples = Y_train.size
def mean_squared_error(y,y_):
return tf.reduce_sum(tf.pow(y_ - y, 2))/(2 * n_examples)

print()
print("\nTest prediction")
print(model.predict(X_test))
print(Y_test)
Y_pred = model.predict(X_test)
print('MSE Test: %.3f' % ( mean_squared_error(Y_test,Y_pred)) )

在启动新内核时我得到了第一次运行

ValueError: Cannot feed value of shape (100, 10) for Tensor 'InputData/X:0', which has shape '(?, 1, 10)'

然后,在第二次

AssertionError: Input dim should be at least 3.

它指的是第二个 LSTM 层。我试图删除第二个 LSTM 和 Dropout 层,但后来我得到了

 feed_dict[net_inputs[i]] = x
IndexError: list index out of range

如果你读到这篇文章,祝你有美好的一天。我你回答一下,非常感谢!!!!

最佳答案

好的,我解决了。我发布它可能对某人有帮助:

X_train = X_train.reshape([-1,1,10])
X_test = X_test.reshape([-1,1,10])

关于python - 使用 tflearn python 将数据输入 lstm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41980184/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com