【问题标题】:google tensor flow crash course. Issues with REPRESENTATION:Programming exercises Task 2: Make Better Use of Latitude谷歌张量流速成课程。 REPRESENTATION 的问题:编程练习 任务 2:更好地利用纬度
【发布时间】:2018-03-31 04:50:37
【问题描述】:

您好,在 tensorflow 速成课程中遇到了另一个障碍……在此页面的表示编程练习中。

https://developers.google.com/…/repres…/programming-exercise

我正在完成任务 2:更好地利用纬度

似乎我将问题范围缩小到当我将原始纬度数据转换为“桶”或范围时,这些数据将在我的功能中表示为 1 或零。我的实际代码和问题在粘贴箱中。任何建议都会很棒!谢谢!

https://pastebin.com/xvV2A9Ac

这是为了将我的 pandas 字典中的原始纬度数据转换为谷歌所称的“桶”或范围。

LATITUDE_RANGES = zip(xrange(32, 44), xrange(33, 45))

我更改了上面的代码并将 xrange 替换为 range,因为 xrange 已经被 python3 弃用了。 这可能是问题吗?使用范围而不是 xrange?我的难题见下文。

def select_and_transform_features(source_df):
  selected_examples = pd.DataFrame()
  selected_examples["median_income"] = source_df["median_income"]
  for r in LATITUDE_RANGES:
    selected_examples["latitude_%d_to_%d" % r] = source_df["latitude"].apply(
      lambda l: 1.0 if l >= r[0] and l < r[1] else 0.0)
  return selected_examples

接下来的两个是运行上述函数并将可能退出的训练和验证数据集转换为纬度范围或桶

selected_training_examples = select_and_transform_features(training_examples)
selected_validation_examples = select_and_transform_features(validation_examples)

这是训练模型

_ = train_model(
    learning_rate=0.01,
    steps=500,
    batch_size=5,
    training_examples=selected_training_examples,
    training_targets=training_targets,
    validation_examples=selected_validation_examples,
    validation_targets=validation_targets)

问题:

oki 所以这就是我对问题的理解。当我运行训练模型时,它会抛出此错误

ValueError: Feature latitude_32_to_33 is not in features dictionary.

所以我调用了 selected_training_examples 和 selected_validation_examples 这就是我发现的。如果我跑

  selected_training_examples = select_and_transform_features(training_examples)

然后,当我调用 selected_training_examples 时,我得到了正确的数据集,这会产生所有特征“桶”,包括特征 #latitude_32_to_33 但是当我运行下一个函数时

selected_validation_examples = select_and_transform_features(validation_examples)

它不会产生任何桶或范围,从而导致

`ValueError: Feature latitude_32_to_33 is not in features dictionary.`

所以我接下来尝试禁用第一个功能

selected_training_examples = select_and_transform_features(training_examples)

我刚刚运行了第二个函数

selected_validation_examples = select_and_transform_features(validation_examples)

如果我这样做,我会得到所需的数据集 selected_validation_examples 。

现在的问题是运行第一个函数不再给我“桶”,我又回到了开始的地方?我想我的问题是这两个功能如何相互影响?并阻止对方给我我需要的数据集?如果我一起运行它们? 提前致谢!

【问题讨论】:

  • 如果您可以编辑您的问题,使其包含代码的最小完整示例 (stackoverflow.com/help/mcve),并且不需要包含指向其他站点的链接以获取基本信息,这将有所帮助。
  • 嗨,python 开发人员给了我解决方案,所以只想分享。 LATITUDE_RANGES = zip(xrange(32, 44), xrange(33, 45)) 只能按其编写方式使用一次,因此我将其放置在解决问题的后续 def select_and_transform_features(source_df) 函数中。再次感谢 rwp 和大家。很抱歉添加了无关的链接。 rwp。我以后不会这样做了。
  • @RadEdje 您可以为自己的问题写一个答案并接受它。 In fact, this is encouraged.
  • 好的,谢谢 MrT :-) 我回答了我的问题...系统说要等待 16 小时才能接受。明天我会接受它,然后尝试关闭此线程。谢谢!

标签: python tensorflow machine-learning artificial-intelligence


【解决方案1】:

python 开发人员给了我解决方案,所以只是想分享。 LATITUDE_RANGES = zip(xrange(32, 44), xrange(33, 45)) 只能按其编写方式使用一次,因此我将其放置在解决问题的后续 def select_and_transform_features(source_df) 函数中。再次感谢大家。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 2013-07-05
    • 2010-12-13
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    相关资源
    最近更新 更多