使用tflearn python将数据输入lstm

时间:2017-02-01 12:44:23

标签: python regression lstm tflearn

我知道这方面已经有一些问题,但我无法找到问题的答案。 对于回归问题,我有一个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

如果你读到这个,祝你有愉快的一天。我你回答了,非常感谢!!!!

1 个答案:

答案 0 :(得分:4)

好的,我解决了。我发布它也许它可以帮助某人:

<ui-select multiple ng-model="data" data-ng-show="condition == 'xyz'" style="margin-top: 5px;" on-select="doSum()" on-remove="doSome()">
    <ui-select-match placeholder="Select timeperiod">
        {{$item.name}}
    </ui-select-match>
    <ui-select-choices repeat="tp in data >
        {{tp.name}}
    </ui-select-choices>
</ui-select>