keras python ライブラリを使用して、最も単純な LSTM を作成したいと思います。
次のコードがあります。
import pandas as pd
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.layers.recurrent import LSTM
X_train = pd.DataFrame( np.array([ [1, 2], [3, 4], [5, 6], [7, 8], [5.1, 6.1], [7.1, 8.1] ]))
y_train = pd.DataFrame( np.array([1, 2, 3, 4, 3, 4]) )
X_test = pd.DataFrame( np.array([ [1.1, 2.1], [3.1, 4.1] ]) )
y_test = pd.DataFrame( np.array([1, 2]) )
model = Sequential()
model.add(LSTM( output_dim = 10, return_sequences=False, input_dim=X_train.shape[1]))
model.add(Dense(input_dim = 10, output_dim=2))
model.add(Activation("linear"))
model.compile(loss="mean_squared_error", optimizer="rmsprop")
model.fit(X_train, y_train)
しかし、うまくいかないようです...
Epoch 1/100
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/keras/models.py", line 489, in fit
shuffle=shuffle, metrics=metrics)
File "/usr/lib/python2.7/site-packages/keras/models.py", line 201, in _fit
ins_batch = slice_X(ins, batch_ids)
File "/usr/lib/python2.7/site-packages/keras/models.py", line 55, in slice_X
return [x[start] for x in X]
File "/usr/lib/python2.7/site-packages/pandas-0.17.0-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 1908, in __getitem__
return self._getitem_array(key)
File "/usr/lib/python2.7/site-packages/pandas-0.17.0-py2.7-linux-x86_64.egg/pandas/core/frame.py", line 1952, in _getitem_array
indexer = self.ix._convert_to_indexer(key, axis=1)
File "/usr/lib/python2.7/site-packages/pandas-0.17.0-py2.7-linux-x86_64.egg/pandas/core/indexing.py", line 1121, in _convert_to_indexer
raise KeyError('%s not in index' % objarr[mask])
KeyError: '[3 4 2 5] not in index'
誰が正確に何がうまくいかないのか説明できますか?
また、行列を転置しようとしましたが、それだけではありません。