i trained my n-network, and everything work fine, except that i don't know how to format my data to make a prediction on data that are not in training and testing set.
I split it into training and testing set, and everything fork fine for
x_train, x_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.1, random_state=0) \n\ni got like 97% acc. Forbestmodel.fit(x_train, y_train, epochs=1, batch_size=5)
print(type(x_test)) print(x_test.dtype) print(x_test.shape)
i have output like
class 'numpy.ndarray' float64 (905, 14)
i made my own example,
z = np.array([1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1]).astype(float)
np.reshape(z, (14,))
but when i try
bestmodel.predict(z)i got error
raceback (most recent call last): \n File "/home/administrator/PycharmProjects/BankMarketinData/main.py", line 81, in \n main()\n File "/home/administrator/PycharmProjects/BankMarketinData/main.py", line 76, in main\n score = bestmodel.predict(z)\n File "/home/administrator/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 1149, in predict\n x, _, _ = self._standardize_user_data(x) \n File "/home/administrator/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 751, in _standardize_user_data\n exception_prefix='input')\n File "/home/administrator/anaconda3/lib/python3.6/site-packages/keras/engine/training_utils.py", line 138, in standardize_input_data\n str(data_shape)) \nValueError: Error when checking input: expected dense_1_input to have shape (14,) but got array with shape (1,)
Can you help me reshape and format this z table, that i can use it for prediciton ?
You need to add the batch dimension with a value of 1:
z = np.array([1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1]).astype(float)
# z.shape is (14,)
z = np.expand_dims(z, axis=0)
# z.shape is now (1, 14)
bestmodel.predict(z)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.