Keras : AttributeError: 'int' object has no attribute 'ndim' when using model.fit
13,048
If train_x
and train_y
are normal Python lists, they don't have the attribute .ndim
. Only Numpy arrays have this attribute representing the number of dimensions.
(https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.ndarray.ndim.html)
Author by
collin
Updated on July 02, 2022Comments
-
collin almost 2 years
when triying to fit the model i get this error
i'm using Keras and every time i try to fit my model
padded_model.fit(train_X, train_y, epochs=50, verbose=1)
i get this error :
'int' object has no attribute 'ndim'
-
umutto about 6 yearsWhat is
train_x
andtrain_y
? They need to be numpy arrays or list of numpy arrays. -
collin about 6 years@umutto i've got train_c and train y using train_test_split : 'train_X, test_X, train_y, 'test_y = train_test_split(padded_docs, y, train_size=0.7, test_size=0.3, random_state=123)'
-
Dr. Snoopy about 6 yearsPlease include the types of train_X and train_y using the type() function in python.
-
-
collin about 6 yearsSo the Problem is that the function fit cannot treate lists ?
-
Joe about 6 yearsBasically yes, but it is also not recommended to use lists. Numpy is a special package to speed up numerical calculations. Using pure Python lists is much slower and not recommended for this purpose. But it is easy to turn a list into a Numpy array if the module is installed. Just pass the list to the array constructor:
x = np.array([1.0, 2.0, 3.0])