Многократное кодирование для категориальной переменной, разделенной пробелами, с использованием функции Indicator_column tenorflow - PullRequest
0 голосов
/ 05 февраля 2019
import tensorflow as tf
feature_names = ['education']

d = dict(zip(feature_names, [["Bachelors","11th"]]))
print(d)
education_vocabulary_list = [
    'Bachelors', 'HS-grad', '11th', 'Masters', '9th', 'Some-college',
    'Assoc-acdm', 'Assoc-voc', '7th-8th', 'Doctorate', 'Prof-school',
    '5th-6th', '10th', '1st-4th', 'Preschool', '12th'] 
education = tf.feature_column.categorical_column_with_vocabulary_list('education', vocabulary_list=education_vocabulary_list)
eductation_indicator = tf.feature_column.indicator_column(education)
feature_columns = [eductation_indicator]
print(feature_columns)

input_layer = tf.feature_column.input_layer(
    features=d,
    feature_columns=feature_columns
)


with tf.train.MonitoredTrainingSession() as sess:
    print(input_layer)
    print(sess.run(input_layer))

В приведенном выше примере я получаю следующий вывод

[<tf.Tensor 'input_layer/concat:0' shape=(2, 16) dtype=float32>][array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
   [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]],
  dtype=float32)]

Я ожидал, что на выходе будет плотный тензор, как указано в ссылке (https://www.tensorflow.org/api_docs/python/tf/feature_column/indicator_column)

По сути, я хочу иметь многократное кодирование для категориальной переменной, разделенной на пробел . Затем я передал бы этот столбец вместе с другими функциями в DNNClassifer для обучения модели.

Как сделатьЯ получаю многократное кодирование для категориальной переменной, разделенной пробелом, с помощью функции Indicator_column tenorflow?

...