Advertisement
Guest User

Untitled

a guest
Mar 30th, 2018
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.22 KB | None | 0 0
  1. ################################################################################################################
  2. #this is to convert the raw latitude data in my pandas dictionary into "buckets" or ranges as google calls them.
  3. #################################################################################################################
  4.  
  5. LATITUDE_RANGES = zip(xrange(32, 44), xrange(33, 45))
  6. #the above code I changed and replaced xrange with just range since xrange is already deprecated python3.
  7. #could this be the problem? using range instead of xrange? see below for my conundrum.
  8.  
  9.  
  10. def select_and_transform_features(source_df):
  11.   selected_examples = pd.DataFrame()
  12.   selected_examples["median_income"] = source_df["median_income"]
  13.   for r in LATITUDE_RANGES:
  14.     selected_examples["latitude_%d_to_%d" % r] = source_df["latitude"].apply(
  15.       lambda l: 1.0 if l >= r[0] and l < r[1] else 0.0)
  16.   return selected_examples
  17.  
  18.  
  19.  
  20. #####################################################################################################################################
  21. #these two are to run the above function and convert may exiting training and validation data sets into ranges or buckets for latitude
  22. ######################################################################################################################################
  23. selected_training_examples = select_and_transform_features(training_examples)
  24. selected_validation_examples = select_and_transform_features(validation_examples)
  25.  
  26.  
  27.  
  28. ###########################
  29. #this is the training model
  30. ###########################
  31. _ = train_model(
  32.     learning_rate=0.01,
  33.     steps=500,
  34.     batch_size=5,
  35.     training_examples=selected_training_examples,
  36.     training_targets=training_targets,
  37.     validation_examples=selected_validation_examples,
  38.     validation_targets=validation_targets)
  39.  
  40.  
  41. #############
  42. #THE PROBLEM
  43. #############
  44.  
  45. #oki so here is how I understand the problem. When I run the training model it throws this error
  46. #ValueError: Feature latitude_32_to_33 is not in features dictionary.
  47. #So I called selected_training_examples  and  selected_validation_examples
  48. #here's what I found. If I run
  49. #  selected_training_examples = select_and_transform_features(training_examples)
  50. #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
  51. #but when I run the next function
  52. #selected_validation_examples = select_and_transform_features(validation_examples)
  53. #it yields no buckets or ranges resulting in the
  54. #ValueError: Feature latitude_32_to_33 is not in features dictionary.
  55. # so I next tried disabling the first function selected_training_examples = select_and_transform_features(training_examples)
  56. #and I just ran the second function selected_validation_examples = select_and_transform_features(validation_examples).
  57. #If I do this, I then get the desired dataset for selected_validation_examples .
  58. #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?
  59. #Thanks in advance!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement