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()