簡體   English   中英

在運行模型時使用 tensorflow 進行訓練時出現 valueError.Evaluate()

[英]valueError while training with tensorflow while running model.Evaluate()

代碼

所有 4 列都是 float64。 我不確定如何處理此錯誤,因為我已經查看了類似的堆棧溢出問題,並且沒有任何關於將其轉換為 numpy 數組和/或 float32 似乎可以解決此問題。

此代碼基於: Google Colab

我剛剛用 mlb 投球數據替換了住房數據,並將 dropna() 應用於訓練和測試數據幀。

謝謝你。

在函數train_model()中,指定數組.astype(float)

所以你需要編輯的行:

features = {name:np.array(value) for name, value in dataset.items()}

... 改成:

features = {name:np.array(value).astype(float) for name, value in dataset.items()}

您還需要在下一個塊中執行此操作:

test_features = {name:np.array(value).astype(float) for name, value in cut_test_df_norm.items()}

完整功能代碼:

def train_model(model, dataset, epochs, label_name,
                batch_size=None):
  """Train the model by feeding it data."""

  # Split the dataset into features and label.
  features = {name:np.array(value).astype(float) for name, value in dataset.items()}
  label = np.array(features.pop(label_name))
  history = model.fit(x=features, y=label, batch_size=batch_size,
                      epochs=epochs, shuffle=True) 
  
  print(features)

  # The list of epochs is stored separately from the rest of history.
  epochs = history.epoch
  
  # To track the progression of training, gather a snapshot
  # of the model's mean squared error at each epoch. 
  hist = pd.DataFrame(history.history)
  mse = hist["mean_squared_error"]

  return epochs, mse

和:

# After building a model against the training set, test that model
# against the test set.
test_features = {name:np.array(value).astype(float) for name, value in cut_test_df_norm.items()}
test_label = np.array(test_features.pop(label_name)) # isolate the label
print("\n Evaluate the new model against the test set:")
my_model.evaluate(x = test_features, y = test_label, batch_size=batch_size)

暫無
暫無

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

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