Data Science Asked by Kahina on September 4, 2021
I doing a simple neural network for Reggression, I didn’t get any error but the MSE & MAE are Nan. The code is:
dataset = pd.read_excel('data_Z.xlsx')
#df = pd.DataFrame(stock, columns= ['X1', 'X2', 'X3', 'X4', 'X5', 'Y1',
'Y2'])
#Variables
x=dataset.iloc[:,0:5]
y=dataset.iloc[:,5].values
y=y.reshape (-1,1)
scaler = MinMaxScaler()
print(scaler.fit(x))
print(scaler.fit(y))
xscale=scaler.transform(x)
yscale=scaler.transform(y)
X_train, X_test, y_train, y_test = train_test_split(xscale, yscale)
model = Sequential()
model.add(Dense(12, input_dim=5, kernel_initializer='normal',
activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='linear'))
model.summary()
model.compile(loss='mse', optimizer='adam', metrics=['mse','mae'])
history = model.fit(X_train, y_train, epochs=150, batch_size=50, verbose=1,
validation_split=0.2)
I cannot understand why?
I had the same problem once when my normalization was "off". I got Nans for all loss functions. Here is what I would do:
scaler.fit(y)
and only do the yscale=scaler.transform(y)
ORx
and y
.Especially if your y
values are in a very different number range from your x
values. Then the normalization is "off" for x
.
Answered by drops on September 4, 2021
Possibilities:
fit(x)
then immediately after fit(y)
probably isn't what you meant to do.)Answered by Ben Reiniger on September 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP