Vasanti
Vasanti

Reputation: 1357

TypeError: argument of type 'float' is not iterable-Tensorflow wide_n_deep_tutorial

I am facing an issue while running the wide_n_deep_tutorial program of TensorFlow https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py on my personal data set with variation is the parameters. I am loading my data from S3.

My target variable is "impression_flag" which the takes the value of either "TRUE" or "FALSE". Below is the code snippet of the train_and_eval method:

    def train_and_eval():
  """Train and evaluate the model."""
  train_file_name, test_file_name = maybe_download()
  df_train = pd.read_csv(
      tf.gfile.Open(train_file_name),
      names=COLUMNS,
      skipinitialspace=True)
  df_test = pd.read_csv(
      tf.gfile.Open(test_file_name),
      names=COLUMNS,
      skipinitialspace=True,
      skiprows=1)
  df_train[LABEL_COLUMN] = (
      df_train["impression_flag"].apply(lambda x: "TRUE" in x)).astype(int)
  df_test[LABEL_COLUMN] = (
      df_test["impression_flag"].apply(lambda x: "TRUE" in x)).astype(int)

  model_dir = tempfile.mkdtemp() if not FLAGS.model_dir else FLAGS.model_dir
  print("model directory = %s" % model_dir)

  m = build_estimator(model_dir)
  m.fit(input_fn=lambda: input_fn(df_train), steps=FLAGS.train_steps)
  results = m.evaluate(input_fn=lambda: input_fn(df_test), steps=1)
  for key in sorted(results):
    print("%s: %s" % (key, results[key]))

While running the code, an error "Type Error: argument of type 'float' is not iterable" is displayed. The following is the screenshot of the error. enter image description here

Any help would be appreciated!

Upvotes: 1

Views: 6905

Answers (1)

Microos
Microos

Reputation: 1768

I got the same problem, it turns out to be caused by the NAN in the first line. Please checks this answer: https://stackoverflow.com/a/40223208/5318060

Upvotes: 3

Related Questions