Home>
Reference site
Using this site as a reference, I was trying to predict behavior by deep learning using my own x and y coordinate data (walking trajectory). I don't know if it matches, but when I changed it to my own data and tried to execute it, when I tried to plot it, the following error message came out.
Length mismatch: Expected axis has 2 elements, new values have 1 elements
Applicable source code
// ---------------
def _load_data (data, n_prev = 20):
"" "
data should be pd.DataFrame ()
"" "
docX, docY = [], []
for i in range (len (data) -n_prev):
docX.append (data.iloc [i: i + n_prev] .as_matrix ())
docY.append (data.iloc [i + n_prev] .as_matrix ())
alsX = np.array (docX)
alsY = np.array (docY)
return alsX, alsY
def train_test_split (df_posixy, test_size = 0.1, n_prev = 20):
"" "
This just splits data to training and testing parts
"" "
ntrn = round (len (df_posixy) * (1-test_size))
ntrn = int (ntrn)
X_train, y_train = _load_data (df_posixy.iloc [0: ntrn], n_prev)
X_test, y_test = _load_data (df_posixy.iloc [ntrn:], n_prev)
return (X_train, y_train), (X_test, y_test)
length_of_sequences = 20
(X_train, y_train), (X_test, y_test) = train_test_split (df_posixy, n_prev = length_of_sequences)
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.layers.recurrent import LSTM
in_out_neurons = 2
hidden_neurons = 500
model = Sequential ()
model.add (LSTM (hidden_neurons, batch_input_shape = (None, length_of_sequences, in_out_neurons), return_sequences = False))
model.add (Dense (in_out_neurons))
model.add (Activation ("linear"))
model.compile (loss = "mean_squared_error", optimizer = "rmsprop", metrics = ['accuracy'])
model.fit (X_train, y_train, batch_size = 600, nb_epoch = 15, validation_split = 0.05)
// --------- So far we have been able to execute
// The part where the error occurred when trying to plot below
predicted = model.predict (X_test)
dataf = pd.DataFrame (predicted [: 100])
dataf.columns = ["predict"]
dataf ["input"] = y_test [: 100]
dataf.plot (figsize = (15, 5))
Data you prepared
Continues 454 lines
Supplemental informationI don't know if it is made in the first place, so if there is something wrong, please.
-
Answer # 1
Related articles
- python: of the results obtained by the for statement, i want to make an empty array like [] into [''']
- python - about deep learning programs using keras
- i don't understand the exercises using python trigonometric functions
- about batch change of file name using python
- please explain the function using the python dictionary
- python - inconsistency in sample size of cnn machine learning with keras
- parameter estimation using python's weighted least squares method (wls)
- parallel processing using python multiprocessingpool and multiprocessingqueue does not work well
- processing using the len function when an integer value is obtained from python standard input
- about external libraries when using multiple versions of python
- python - i want to separate by a specific word using the split function
- python - image recognition using cnn keras multiple inputs
- python - reinforcement learning of tag does not go well with open ai gym
- python 3x - how to rename a folder created using jupyternotebook
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - how to keep displaying results while running pandas dataframe
- python 3x - processing to jump to the link destination using chrome driver in python
- python - error in image binarization using cv2adaptivethreshold function
- i want to adjust the execution result using the while statement in python as expected
- python - i want to put the image file path in a variable and open it using that variable
Related questions
- python 3x - tensorflow modelpredict () error
- python 3x - inflating table data using gan
- python 3x - keras predict results do not change
- python - loss coefficient does not decrease at all | stock price forecast using deep learning
- python 3x - about python keras model building
- python 3x - python keras about the shape of learning data
- python - about learning mnist data with keras
- resizing the output image with ipythondisplay on jupyter notebook
- python - error that no data is entered in x_train_b
- python - i want to resolve the error message
model.save_weights ('mnist_mlp_weights.hdf5') // Save weights
model.load_weights ('mnist_mlp_weights.hdf5') // load weights
predicted = model.predict (X_train)
df_predicted = pd.DataFrame (predicted, columns = list ('xy'))
plt.plot (df_predicted ["x"], df_predicted ["y"], 'ro')