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)

Share:
13,048
collin
Author by

collin

Updated on July 02, 2022

Comments

  • collin
    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
      umutto about 6 years
      What is train_x and train_y? They need to be numpy arrays or list of numpy arrays.
    • collin
      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
      Dr. Snoopy about 6 years
      Please include the types of train_X and train_y using the type() function in python.
  • collin
    collin about 6 years
    So the Problem is that the function fit cannot treate lists ?
  • Joe
    Joe about 6 years
    Basically 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])