我总是用我的模型预测负值

时间:2018-05-30 08:10:12

标签: python tensorflow neural-network keras feed-forward

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

我将NN定义为:

features = Input(shape=(18,))

LAYER1

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

LAYER2

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

LAYER3

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

LAYER4

X = Dense(512)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)

LAYER5

X = Dense(256)(X)
X = BatchNormalization()(X)
X = Dropout(0.1)(X)
X = LeakyReLU(alpha=0.2)(X)

LAYER6

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)

0 个答案:

没有答案