Reputation: 3453
I'm trying to make my_feature_columns list from this dataset. I'm reading it with this code:
train = pd.read_csv(train_path, names=CSV_COLUMN_NAMES, header=0)
train = train.drop(['Name', 'SibSp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'], axis=1)
train.fillna(0, inplace=True)
I just want to use "Pclass", "Sex" and "Age". Since Sex
only have 2 possible values I write this code:
my_feature_columns = [
tf.feature_column.numeric_column(key='Pclass'),
tf.feature_column.categorical_column_with_vocabulary_list(key="Sex", vocabulary_list=["male", "female"]),
tf.feature_column.numeric_column(key='Age'),
]
Then I instanciates the Classifier:
classifier = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
hidden_units=[10, 10],
n_classes=2)
But I'm getting
ValueError: Items of feature_columns must be a _DenseColumn. You can wrap a categorical column with an embedding_column or indicator_column. Given: _VocabularyListCategoricalColumn(key='Sex', vocabulary_list=('male', 'female'), dtype=tf.string, default_value=0, num_oov_buckets=0)
I'm totally new with TensorFlow and I have no idea what's going on. I'll apreciate all kind of help, thanks in advance and sorry about my English.
Upvotes: 14
Views: 8522
Reputation: 231
There is another way According to This Source Code:
So:
categorical_column = tf.feature_column.categorical_column_with_vocabulary_list(key="Sex", vocabulary_list=["male", "female"], default_value=0)
my_feature_columns = [
tf.feature_column.numeric_column(key='Pclass'),
embedded_group_column = tf.feature_column.embedding_column(categorical_column,dimension=number_of_categories)
tf.feature_column.numeric_column(key='Age')
]
Good Luck!
Upvotes: 2
Reputation: 3453
Reading again the documentation I realised that
Indicator columns and embedding columns never work on features directly
So I corrected my code:
categorical_column = tf.feature_column.categorical_column_with_vocabulary_list(key="Sex", vocabulary_list=["male", "female"], default_value=0)
my_feature_columns = [
tf.feature_column.numeric_column(key='Pclass'),
tf.feature_column.indicator_column(categorical_column),
tf.feature_column.numeric_column(key='Age')
]
And works like a charm!
Upvotes: 25