为什么这个神经网络在python中为所有预测提供NaN?
我一直试图创建的神经网络模型似乎只创建了Nan预测。我使用的csv表只有数字,但是有一些空值,我用x.dropna删除了这些值。是否有其他与数据有关的内容可以删除此错误?没有分类数据,只有数字为什么这个神经网络在python中为所有预测提供NaN?,python,Python,我一直试图创建的神经网络模型似乎只创建了Nan预测。我使用的csv表只有数字,但是有一些空值,我用x.dropna删除了这些值。是否有其他与数据有关的内容可以删除此错误?没有分类数据,只有数字 def fits(x,y): sc_x=StandardScaler() sc_y=StandardScaler() x=sc_x.fit_transform(x) y=y.values.reshape(-1,1) y=sc_y.fit_transform(y) d
def fits(x,y):
sc_x=StandardScaler()
sc_y=StandardScaler()
x=sc_x.fit_transform(x)
y=y.values.reshape(-1,1)
y=sc_y.fit_transform(y)
def create_model():
model = Sequential()
model.add(Dense(50, input_dim=15, activation='softplus', kernel_initializer='lecun_uniform'))
model.add(Dense(1, activation='relu',kernel_initializer='lecun_uniform'))
optimizer = SGD(lr=0.001)
model.compile(loss='mse', optimizer=optimizer, metrics=['mean_absolute_error'])
return model
from sklearn.pipeline import Pipeline
neural_network = KerasRegressor(build_fn=create_model,
epochs=100,
batch_size=40,
verbose=0)
fits(x_train,y_train)
fits(x_test,y_test)
neural_network.fit(x_train,y_train)
y_pred=neural_network.predict(x_test)
error=np.mean(abs(y_pred-y_test))
error
此错误显示为Nan。对于我的表格,我也看到预测值都是Nan。我还尝试使用交叉验证来查看是否有任何错误
pipe=Pipeline([('scaler',StandardScaler()),('model',neural_network)])
from sklearn.model_selection import cross_val_score,cross_val_predict
y_pred1 = cross_val_predict(pipe, x, y, cv=5)
error1=abs(y-y_pred1)
print(np.mean(error1))
然而,这仍然无济于事