簡體   English   中英

Keras 回歸 | 從配備多個 y 參數的 model 獲取單個預測

[英]Keras regression | Get a single prediction from a model fitted with multiple y parameters

我有以下代碼來創建自定義損失 function 使用數據集中的附加特征(不是輸入特征)作為參數。 該代碼工作正常,沒有錯誤,但我想確保它對正確的“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?

當我使用此 model 進行預測時,它是否僅對“Y”或 Y 與附加特征的組合進行預測,因為 model.fit() 將“Y”和“特征”作為 y 參數進行訓練,但 Z449D84CAF3.683053 predict() 只給出一個 output。 如果預測是 Y 和附加特征的組合,我怎樣才能只提取 Y?

model 僅預測“Y”。 損失 function 在預測時沒有調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM