I want to label the elements of 4 numbers as A (1) or B (0) and classify the newly given 4 numbers as A or B.
Now, the following code works well until learning, but if you try to predict the data with four numbers called test.csv with predict () "ValueError: Error when checking input: expected dense_1_input to The error code "have shape (4,) but got array with shape (1,)" will appear.
By increasing the input data by 3 to form a 4x4 matrix, you can predict it.
I'm assuming that I'm going to input 4 data for each row, so I thought it would work with a 1x4 matrix, but I want to know why an error occurs.
* Add shape result *
The shape of each matrix is as follows. Now, testdata is the data I want to predict and data is the teacher data.
>>>print (testdata.shape) (Four,) >>>print (data.shape) (100, 4) >>>
Part of teacher data
9.60385,11.0032,9.32986,9.25753 9.37304,13.0028,11.0855,9.64098 8.40733,12.6233,10.2337,8.79376 8.73675,12.249,8.87519,7.89159 , , , 11.7207,14.0737,10.9952,9.37442 12.7404,16.0793,14.1397,12.5642 11.2507,15.38,12.9987,12.0801 11.9871,15.1148,11.6168,10.9482 11.0797,13.8117,9.74263,8.2056 11.6802,15.2681,12.8943,12.1861
import numpy as np from keras.utils import np_utils from keras.models import Sequential from keras.layers import Dense, Activation data = np.loadtxt (fname = "CSV/teacher.csv", delimiter = ",") testdata = np.loadtxt (fname = "CSV/test.csv", delimiter = ",") labels = np.array ( [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 , 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 , 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ) labels = np_utils.to_categorical (labels) model = Sequential () model.add (Dense (10, input_dim = 4)) model.add (Activation ('relu')) model.add (Dense (2, activation = 'softmax')) model.compile ('rmsprop', 'categorical_crossentropy', metrics = ['accuracy']) model.fit (data, labels, epochs = 100, validation_split = 0.2) test = model.predict (testdata) print (test)
Answer # 1
Change testdata shape.
testdata = testdata.reshape ((1,4))
- python 3x - about value error in keras predict
- python - error in modeling keras rnn
- python 3x - i want to fix the input value error that i got while streaming insert json data into bigquery
- python - judgment if the value is nan or not a valid url
- error in import xlrd of python file from cakephp
- python - how to resolve attribute error
- indent error doesn't go away, python
- python 3x - the output result of the numerical value obtained by web scraping becomes 0
- python - an error occurs in the if statement program that compares the size of numbers
- python - sklearn, svm error
- python - error in image binarization using cv2adaptivethreshold function
- python - in raspberry pi, the error occurs only in the case of the automatic start program using systemd
- python - absolute value behavior of complex numbers in numpy
- python 3x - i want to save the value of a variable in memory
- python error compare with future stock price
- python - categorical_crossentoropy error does not resolve
- put the maximum value of the list of variables in the objective function with python pulp
- readcsv error in python
- python - i want to display an image with pysimplegui, but an error occurs
- python - error when scraping with selenium and firefox