我正在做一个回归问题,我有18个功能。每当我尝试预测值时,它总是给我负值。有人可以帮忙吗?
我将NN
定义为:
features = Input(shape=(18,))
X = Dense(1024)(features)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
X = Dense(1024)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
X = Dense(1024)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
X = Dense(512)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
X = Dense(256)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
X = Dense(128)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)
Corr = Dense(1)(X)
model = Model(inputs = features, outputs=Corr)
model.compile(optimizer = 'Sgd', loss=huber_loss, metrics=['mse', 'mae'])
model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=20, batch_size=512, verbose=1)
Huber损失是:
def huber_loss(y_true, y_pred):
return tf.losses.huber_loss(y_true,y_pred)