0

I'm working for an environmental data lab. I want to predict water pollution using ML(mlp), but now I have a little problem here: I have some data about water pollution and weather condition:

data shape : (963, 7), weather data which means wind speed, temp, pre, and so on

(weather data which means wind speed, temp, pre, and so on)

data shape : (963, 2), another data which means water pollution indicator

(another data which means water pollution indicator)

I'm using this code:

x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=42, test_size=0.2)
x_test, x_val, y_test, y_val = train_test_split(x_test, y_test, random_state=42, 
test_size=0.5)

model = Sequential()
model.add(Dense(10,activation='relu'))
model.add(Dense(10))
model.add(Dense(8))
model.add(Dense(2), ) # input col 2개 이므로 output도 2개

model.compile(loss='mse', optimizer='adam', metrics=['mse'])

model.fit(x_train, y_train, epochs=100, batch_size=1, validation_data=(x_val, y_val))
loss, mse = model.evaluate(x_test, y_test, batch_size=1)
print('acc : ', mse)

y_predict = model.predict(x_test)
print(y_predict)

def RMSE(y_test, y_predict):
    return np.sqrt(mean_squared_error(y_test, y_predict))
print('RMSE : ', RMSE(y_test, y_predict)) 

r2_y_predict = r2_score(y_test, y_predict)
print('R2 : ', r2_y_predict)

There is an error like this:

y_true and y_pred have different number of output (1!=2)

What is causing this error and how can I solve it?

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
son
  • 1
  • Consider checking your dataframe sizes: either increase or decrease one to match and be equal. – Salek Sep 16 '21 at 04:29
  • 2
    Does this answer your question? [Calculating mean square error return y\_true and y\_pred have different number of output (1!=10)](https://stackoverflow.com/questions/60988136/calculating-mean-square-error-return-y-true-and-y-pred-have-different-number-of) – Salek Sep 16 '21 at 04:33
  • your right thanks. think i have to do some more study about layers input and output shape. – son Sep 16 '21 at 04:43

0 Answers0