- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Chollet 的书 Deep Learning with Python 的第 3.7 节。
该项目旨在找出 1970 年代波士顿特定郊区的房屋中位价。
https://github.com/fchollet/deep-learning-with-python-notebooks/blob/master/3.7-predicting-house-prices.ipynb
在“使用 K 折验证验证我们的方法”部分,我尝试运行这段代码:
num_epochs = 500
all_mae_histories = []
for i in range(k):
print('processing fold #', i)
# Prepare the validation data: data from partition # k
val_data = train_data[i * num_val_samples: (i + 1) * num_val_samples]
val_targets = train_targets[i * num_val_samples: (i + 1) * num_val_samples]
# Prepare the training data: data from all other partitions
partial_train_data = np.concatenate(
[train_data[:i * num_val_samples],
train_data[(i + 1) * num_val_samples:]],
axis=0)
partial_train_targets = np.concatenate(
[train_targets[:i * num_val_samples],
train_targets[(i + 1) * num_val_samples:]],
axis=0)
# Build the Keras model (already compiled)
model = build_model()
# Train the model (in silent mode, verbose=0)
history = model.fit(partial_train_data, partial_train_targets,
validation_data=(val_data, val_targets),
epochs=num_epochs, batch_size=1, verbose=0)
mae_history = history.history['val_mean_absolute_error']
all_mae_histories.append(mae_history)
mae_history = history.history['val_mean_absolute_error']
最佳答案
您的代码中的问题是,当您编译模型时,您没有添加特定的 ' mae
' 度量。
如果您想添加 ' mae
' 度量在你的代码中,你需要这样做:
model.compile('sgd', metrics=[tf.keras.metrics.MeanAbsoluteError()])
model.compile('sgd', metrics=['mean_absolute_error'])
val_mean_absolute_error
或
val_mae
.最有可能的是,如果您像我在选项 2 中演示的那样编译模型,您的代码将使用“
val_mean_absolute_error
”。
build_model()
函数)
关于python-3.x - 如何从 Chollet Deep Learning with Python 中解决 KeyError : 'val_mean_absolute_error' Keras 2. 3.1 和 TensorFlow 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60053547/
对于我的家庭作业,如果用户输入的键(文本)包含任何非字母字符并重新提示,我被告知要引发一个键错误。到目前为止,我有这个似乎有效但显然没有使用预期的 try/except 结构 key=input("P
编写try/except语句时,是否使用 except KeyError: 或 except KeyError as e: 我得到了相同的结果。 两者有什么区别? KeyError as e 只是更具
我在使用 Python Flask 和 Flask-Mail 库时遇到问题。 我收到一个错误: KeyError: 'mail' 谁能帮我解决这个问题? 我的代码是: # -*- coding: ut
我正在尝试获取 Twitter 登录页面中的隐藏元素。我遵循的过程只是获取该页面中的隐藏元素。但问题是,当我尝试获取这些元素的值时,我遇到了关键错误。代码是: import requests,
我正在尝试将 atexit 处理程序添加到我的代码中。但我发现如果我导入了线程模块,它会给我一个 KeyError 异常。这是 python 线程模块中的错误吗? #!/usr/bin/python2
我正在从 Python2.7 numba 代码转换为 Python3.4。此函数pairwise_distance 将多维数组X 和Y 转换为距离矩阵。 但是,我使用 numba 装饰器 @jit 来
我有 2 个用于生产和开发的独立设置文件以及一个通用的 base.py 设置文件 base.py SECRET_KEY = r"!@#$%^&123456" prod.py from .base im
下面的代码 for k in list(g_score.keys()): print(g_score[k]) 返回 KeyError对我来说: Traceback (most recent c
我收到了一份。在Spyder中第二次从子文件夹导入库时出错,但第一次(重新启动Spyder后)或在Spyder外导入时工作正常。。代码是:。其中,test_lib.py只是。输出结果为:。当库不在子文
我希望以下列方式获取一个对象: Collection.objects.get(name='name', type='library', owner=owner, parent=parent) 不幸的是
如何加入这两个文本文档? 文档 1: 1000001 10:0.471669 250:0.127552 30:0.218773 64:0.249413 1000002 130:0.0839656 10
这段代码有什么问题? 这是我的 HTML: File: 这是我的 Python 脚本: #! /usr/bin/env python import os, sys; from mod_py
我正在尝试在 Linux 中使用 cron 运行一个 Python 脚本,它应该构建一个数据字典。我正在尝试使用 datetime().now().time() 作为字典中的键,但它似乎会引发错误。
我正在尝试更改列或处理列,但出现一些 keyError 错误。从事芝加哥犯罪数据分析工作。 例如当我尝试运行时 ds["DATE OF OCCURRENCE"] = pd.to_datetime([d
我有一个包含以下列的数据框,我只是想通过转换现有列来添加新列。我不明白为什么我会收到此错误,特别是考虑到数据框很好并且我可以在 Zip 上使用 groupby 而不会出现任何索引问题。 print(d
我正在尝试使用 ffmpeg 从视频文件中获取分辨率高度和音频比特率,但出现以下错误,但并不能告诉我太多信息: File "/home/user/code/python/reduce_video_si
我正在为每个单独的州分配区域。我的代码从一个 excel 文件中读取,大约有 30k 行。我建立了一个字典,将每个州分配给一个地区,并为每个州名称分配州缩写。我正在尝试创建一个列来填充每个行项目的区域
我仍在努力学习 Python 词典的来龙去脉。当我运行这个: #!/usr/bin/env python3 d = {} d['foo']['bar'] = 1 我收到 KeyError: 'foo'
我正在尝试使用 Tensorflow 训练线性回归器。 如果我通过自动确定实值列来实例化学习器,则拟合工作正常。 auto_feature_columns = tf.contrib.learn
我正在尝试编写一个可以从YouTube下载整个播放列表的代码。它适用于某些播放列表,但不适用于少数播放列表。我在下面的代码中显示的播放列表之一。也可以随时在此代码上添加更多功能。 如果已有下载该播放列
我是一名优秀的程序员,十分优秀!