【发布时间】:2020-12-09 03:46:00
【问题描述】:
我有以下代码来创建自定义损失函数,使用数据集中的附加特征(不是输入特征)作为参数。代码运行良好,没有错误,但我想确保它对正确的“Y”做出预测。
def custom_loss(data, y_pred):
y_true = data[:, 0]
feature = data[:, 1]
return K.mean(K.square((y_pred - y_true) + K.std(y__pred - feature)))
def create_model():
# create model
model = Sequential()
model.add(Dense(5, input_dim=1, activation="relu"))
model.add(Dense(1, activation="linear"))
(train, test) = train_test_split(df, test_size=0.3, random_state=42)
model = models.create_model(train["X"].shape[1])
opt = Adam(learning_rate=1e-2, decay=1e-3/200)
model.compile(loss=custom_loss, optimizer=opt)
model.fit(x=train["X"], y=train[["Y", "feature"]], validation_data=(test["X"], test[["Y", "feature"]]), batch_size = 8, epochs=90)
predY = model.predict(test["X"]) # what does the model predict here?
当我使用此模型进行预测时,它是仅对“Y”还是对 Y 和附加特征的组合进行预测,因为 model.fit() 将“Y”和“特征”作为 y 参数进行训练但是 model.predict( ) 只给出一个输出。如果预测是 Y 和附加特征的组合,我怎样才能只提取 Y?
【问题讨论】:
标签: python tensorflow keras