Tensorflow 1.x feature_columns的项必须为_FeatureColumn。给定类型为列表

时间:2019-11-03 06:58:01

标签: python python-3.x tensorflow machine-learning linear-regression

我正在使用TensorFlow 1.15进行机器学习项目,在该项目中,我正在使用tf.feature_column创建功能部件列,但是在此方面存在错误。

这是我定义feature columns的方式:

# Define feature columns

is_male = tf.feature_column.categorical_column_with_vocabulary_list('is_male', vocabulary_list=['False', 'True'])
plurality = tf.feature_column.categorical_column_with_vocabulary_list('plurality', vocabulary_list=['Single(1)', 'Twins(2)', 'Triplets(3)', 'Quadruplets(4)', 'Quintuplets(5)'])
wide_columns = [is_male, plurality]
mother_age = tf.feature_column.numeric_column(key="mother_age", shape=10)
gestation_weeks = tf.feature_column.numeric_column(key="gestation_weeks", shape=10)
deep_columns = [mother_age,gestation_weeks]
feature_cols = [wide_columns, deep_columns]

这是我得到的确切错误:

  

ValueError:feature_columns的项必须为_FeatureColumn。给定的(类型):[VocabularyListCategoricalColumn(key ='is_male',vocabulary_list =('False','True'),dtype = tf.string,default_value = -1,num_oov_buckets = 0),VocabularyListCategoricalColumn(key ='plurality', vocabulary_list = {'Single(1)','Twins(2)','Triplets(3)','Quadruplets(4)','Quintuplets(5)'),dtype = tf.string,default_value = -1, num_oov_buckets = 0)]。

1 个答案:

答案 0 :(得分:0)

我认为package com.luv2code.springdemo.mvc; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HomeController { @RequestMapping("/") public String showPage() { return "main-menu"; } } 包含两个列表,因此您正在传递feature_cols。我相信您想做的是feature_cols = [[is_male, plurality], [mother_age, gestation_weeks]]