2

我正在做一个回归问题,我有 18 个特征。每当我尝试预测这些值时,它总是给我负值。有人可以帮忙吗?

我将我定义NN为:

features = Input(shape=(18,))

第一层

X = Dense(1024)(features)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)

第 2 层

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)
4

0 回答 0