Google张量流崩溃课程.表示问题:编程练习任务2:更好地利用纬度 [英] google tensor flow crash course. Issues with REPRESENTATION:Programming exercises Task 2: Make Better Use of Latitude

查看:195
本文介绍了Google张量流崩溃课程.表示问题:编程练习任务2:更好地利用纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好在Tensorflow崩溃过程中遇到了另一个障碍...在本页的表示法编程练习中

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

我正在执行任务2:更好地利用纬度

似乎我将问题范围缩小到了将原始纬度数据转换为桶"或将在我的地图项中表示为1或0的范围时的问题.我遇到的实际代码和问题在粘贴容器中.任何建议都很好!谢谢!

https://pastebin.com/xvV2A9Ac

这是将我的pandas词典中的原始纬度数据转换为桶"或Google称之为的范围.

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)

问题:

好的,这就是我对问题的理解方式.当我运行训练模型时,会引发此错误

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.

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

解决方案

一个python开发人员为我提供了解决方案,因此只想分享. LATITUDE_RANGES = zip(xrange(32,44),xrange(33,45))只能以一种编写方式使用,因此我将其放置在成功解决问题的def select_and_transform_features(source_df)函数中.再次感谢大家.

Hi got into another roadblock in tensorflow crashcourse...at the representation programming excercises at this page.

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

I'm at Task 2: Make Better Use of Latitude

seems I narrowed the issue to when I convert the raw latitude data into "buckets" or ranges which will be represented as 1 or zero in my feature. The actual code and issue I have is in the paste bin. Any advice would be great! thanks!

https://pastebin.com/xvV2A9Ac

this is to convert the raw latitude data in my pandas dictionary into "buckets" or ranges as google calls them.

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

the above code I changed and replaced xrange with just range since xrange is already deprecated python3. could this be the problem? using range instead of xrange? see below for my conundrum.

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

The next two are to run the above function and convert may exiting training and validation data sets into ranges or buckets for latitude

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

this is the training model

_ = 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)

THE PROBLEM:

oki so here is how I understand the problem. When I run the training model it throws this error

ValueError: Feature latitude_32_to_33 is not in features dictionary.

So I called selected_training_examples and selected_validation_examples here's what I found. If I run

  selected_training_examples = select_and_transform_features(training_examples)

then I get the proper data set when I call selected_training_examples which yields all the feature "buckets" including Feature #latitude_32_to_33 but when I run the next function

selected_validation_examples = select_and_transform_features(validation_examples)

it yields no buckets or ranges resulting in the

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

so I next tried disabling the first function

selected_training_examples = select_and_transform_features(training_examples)

and I just ran the second function

selected_validation_examples = select_and_transform_features(validation_examples)

If I do this, I then get the desired dataset for selected_validation_examples .

The problem now is running the first function no longer gives me the "buckets" and I'm back to where I began? I guess my question is how are the two functions affecting each other? and preventing the other from giving me the datasets I need? If I run them together? Thanks in advance!

解决方案

a python developer gave me the solution so just wanted to share. LATITUDE_RANGES = zip(xrange(32, 44), xrange(33, 45)) can only be used once the way it was written so I placed it inside the succeding def select_and_transform_features(source_df) function which solved the issues. Thanks again everyone.

这篇关于Google张量流崩溃课程.表示问题:编程练习任务2:更好地利用纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆