[英]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.