Feature (key: gender) cannot have rank 0

Hello guys,
Can you help me?
I don’t know, why I am getting this error.

import pandas as pd
import tensorflow as tf

def main():
dataframe = pd.read_csv(“music.csv”)
print(dataframe.columns)
y_label = dataframe.pop(“age”)

CATEGORICAL_COLUMNS = ["genre"]
NUMERIC_COLUMNS = ["gender"]

feature_columns = []
for feature_name in CATEGORICAL_COLUMNS:
    vocabulary = dataframe[feature_name].unique()
    feature_columns.append(tf.feature_column.categorical_column_with_vocabulary_list(feature_name, vocabulary))

for feature_name in NUMERIC_COLUMNS:
    feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32))

def make_input_fn(data_df, label_df, num_epochs=10, shuffle=True, batch_size=32):
    def input_function():
        ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df))
        if shuffle:
            ds.shuffle(1000)
        ds.batch(batch_size).repeat(num_epochs)
        return ds
    return input_function

print(feature_columns)

data_totrain_fn = make_input_fn(dataframe, y_label)
normal = make_input_fn(data_df=dataframe, label_df=y_label, batch_size=1, num_epochs=1, shuffle=False)
linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(data_totrain_fn)
result = linear_est.evaluate(normal)
print(result['accuracy'])

if name == “main”:
main()

This needs more info…

  1. Where does the error occur?
  2. Can you show some of your dataset (perhaps the top 10 rows?)

Also, does this help?

You should assign back to the dataset (i.e ds) in input_function as described below

def make_input_fn(data_df, label_df, num_epochs=10, shuffle=True, batch_size=32):
  def input_function():
    ds = tf.data.Dataset.from_tensor_slices((dict(data_df), label_df))
    ds.batch(10)
    if shuffle:
      ds = ds.shuffle(1000)
    ds = ds.batch(batch_size).repeat(num_epochs)
    return ds
  return input_function

If you struck again. Please share the music.csv dataset to replicate the issue. Thank you.