title: Tensorflow DNNClassifier error: [Labels must <= n_classes - 1] [Condition x <= y did not hold element-wise:x
body: <p>I am trying to use the tf.estimator.DNNClassifier to predict the monthly price for a dataset. However when running the program I am getting an error with the DNNClassifier stating that the labels is not &lt;= n_classes -1. </p>
  
  <pre><code>InvalidArgumentError (see above for traceback): assertion failed: [Labels must &lt;= n_classes - 1] [Condition x &lt;= y did not hold element-wise:x (dnn/head/ToFloat:0) = ] [[51][58][50]...] [y (dnn/head/assert_range/Const:0) = ] [1]
  </code></pre>
  
  <p>It seems as if it is not recognizing my feature columns in the DNN classifier. The following code is what I am running.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import tensorflow as tf
  import pandas as pd
  import numpy as np
  from sklearn.model_selection import train_test_split
  from sklearn.preprocessing import StandardScaler
  
  
  df = pd.read_csv('./csv/lmtensordata.csv')
  
  
  deep_feat = df.drop(columns=['monthly_price'], axis=1)
  deep_label = df['monthly_price']
  
  df.info()
  df.head()
  
  numerical_columns = [col for col in df.columns if (df[col].dtype=='int64' or df[col].dtype=='float64')]
  
  
  categorical_columns = [col for col in deep_feat.columns if len(deep_feat[col].unique()) == 2 or deep_feat[col].dtype == 'O']
  
  continuous_columns = [col for col in deep_feat.columns if len(deep_feat[col].unique()) &gt; 2 and (deep_feat[col].dtype == 'int64' or deep_feat[col].dtype=='float64')]
  
  
  
  # making a train test split
  X_T, X_t, y_T, y_t = train_test_split(deep_feat, deep_label, test_size=0.3)
  
  cols_to_scale = continuous_columns[:]
  
  # scaling the listed columns
  scaler = StandardScaler()
  X_T.loc[:,cols_to_scale] = scaler.fit_transform(X_T.loc[:,cols_to_scale])
  X_t.loc[:,cols_to_scale] = scaler.fit_transform(X_t.loc[:,cols_to_scale])
  
  
  continuous_feat_cols = [tf.feature_column.numeric_column(key=col) for col in continuous_columns]
  
  feat_cols = continuous_feat_cols
  
  
  input_fun = tf.estimator.inputs.pandas_input_fn(X_T,y_T,batch_size=50,num_epochs=1000,shuffle=True)
  pred_input_fun = tf.estimator.inputs.pandas_input_fn(X_t,batch_size=50,shuffle=False)
  
  DNN_model = tf.estimator.DNNClassifier(hidden_units=[10,10,10], feature_columns=feat_cols, n_classes=2)
  
  DNN_model.train(input_fn=input_fun, steps=5000)
  
  predictions = DNN_model.predict(pred_input_fun)
  
  res_pred = list(predictions)
  print(res_pred[0])</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I print out my feat_cols this is what I am getting.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>[  
     _NumericColumn(key='car_year',
     shape=(1,),
     default_value=None,
     dtype=tf.float32,
     normalizer_fn=None),
     
     _NumericColumn(key='make_model_bucket',
     shape=(1,
     ),
     default_value=None,
     dtype=tf.float32,
     normalizer_fn=None),
     
     _NumericColumn(key='mileage',
     shape=(1,
     ),
     default_value=None,
     dtype=tf.float32,
     normalizer_fn=None),
     
     _NumericColumn(key='years_licensed_bucket',
     shape=(1,
     ),
     default_value=None,
     dtype=tf.float32,
     normalizer_fn=None),
     
     _NumericColumn(key='zip_bucket',
     shape=(1,
     ),
     default_value=None,
     dtype=tf.float32,
     normalizer_fn=None)
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is also the df.head() output of the dataset I am working with.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
  RangeIndex: 33588 entries, 0 to 33587
  Data columns (total 6 columns):
  car_year                 33588 non-null int64
  make_model_bucket        33588 non-null int64
  mileage                  33588 non-null int64
  years_licensed_bucket    33588 non-null int64
  zip_bucket               33588 non-null float64
  monthly_price            33588 non-null int64
  dtypes: float64(1), int64(5)
  memory usage: 1.5 MB</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am not sure what I should be inputting for the n_classes or if something is wrong with my feature columns.</p>
  
  <p>Any help is much appreciated!</p>