google tensor flow crash course. Issues with REPRESENTATION:Programming exercises Task 2: Make Better Use of Latitude

為{幸葍}努か 提交于 2019-12-14 04:06:54

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/49584365/google-tensor-flow-crash-course-issues-with-representationprogramming-exercise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!