Assertion Error when training DNNClassifier

I’m trying to create a DNN classifier and am running into the following error:

Invalid argument: assertion failed: [Labels must be <= n_classes – 1] [Condition x <= y did not hold element-wise:] [x (head/losses/labels:0) = ] [[3][2][4]…] [y (head/losses/check_label_range/Const:0) = ] [4]

I am following the general structure from and am not sure what I’m doing wrong.

In my data, there are 255 columns and 4 possible classifications for each row.

I have excluded the imports

training_data = pd.read_csv(data_file)
target_data = pd.read_csv(target_file)
train_y = training_data.pop(‘StateCode’)
target_y = target_data.pop(‘StateCode’)
def input_fn(features, labels, training=True, batch_size=256):
# Convert the inputs to a Dataset.
dataset =, labels))
# Shuffle and repeat if you are in training mode.
if training:
dataset = dataset.shuffle(1000).repeat()

return dataset.batch(batch_size)
my_feature_columns = []
for key in training_data.keys():
labels = list(training_data.columns)
classifier = tf.estimator.DNNClassifier(
# Two hidden layers of 30 and 10 nodes respectively.
hidden_units=[30, 10],
# The model must choose between 4 classes.

input_fn=lambda: input_fn(training_data, train_y, training=True),


Any help would be appreciated.

submitted by /u/rk2danker
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *