Dimensions must be Equal, but are 3 and 5 for...with input shapes: [32,3], [32,5]

Asked

Viewed 32 times

0

I’m building a neural network, and I find the following mistake:

ValueError: Dimensions must be equal, but are 3 and 5 for '{{node mean_absolute_error/sub}} = Sub[T=DT_FLOAT](sequential/dense_1/Sigmoid, IteratorGetNext:1)' with input shapes: [32,3], [32,5].

Since I have used other bases in the same code and it worked. And the bases are arranged in the same way.

I have tried changing the Oss, changing the optimizer or metric, and nothing. I also can’t find anything in the forums.

import pandas as pd
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
import numpy as np


entradas = pd.read_csv('class_in.csv')
saidas = pd.read_csv('class_out.csv')

X = entradas
X = np.array(X)
Y = saidas
Y = np.array(Y)
onehot_encoder=OneHotEncoder(sparse=False)
reshaped=Y.reshape(len(Y), 1)
y_onehot=onehot_encoder.fit_transform(reshaped)
print (X)
print(y_onehot)

callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=50)

from sklearn.model_selection import StratifiedKFold
K = 5
                         
skf = StratifiedKFold(n_splits = K, shuffle = True) 

performance = [None] * (K)
fold = 0

for train_val, test in skf.split(X,Y):
  model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(300, input_dim=200, activation=tf.nn.sigmoid),
  tf.keras.layers.Dense(3, activation=tf.nn.sigmoid)
  ])

  model.compile(optimizer='sgd',
              loss='mae',
              metrics=['accuracy'])

  x_train, x_val, y_train, y_val = train_test_split(X[train_val], y_onehot[train_val], test_size=0.2, stratify=Y[train_val])


  model.fit(x=x_train, y=y_train, epochs=1000000, callbacks=[callback], validation_data=(x_val,y_val))
  performance[fold] = model.evaluate(X[test], y_onehot[test], verbose=0)
  fold = fold + 1
 
  • Which line exactly is giving the error? Can you add the result of the following commands, please? .head() ’s output.head()

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.