【问题标题】:Tensorflow : Creating a loop for feature variablesTensorflow:为特征变量创建循环
【发布时间】:2017-11-20 21:17:46
【问题描述】:

我在 TensorFlow 中有多个特征列,我正在尝试创建循环以避免手动输入来创建特征列,但它不起作用。下面是我需要创建特征列的所有列的列表(这只是一个虚拟数据,但如果我们有数百列怎么办)。

num_preg = tf.feature_column.numeric_column('Number_pregnant')
glucose_conc = tf.feature_column.numeric_column('glucose_concentration')
blood_prs = tf.feature_column.numeric_column('blood_pressure')
Tricep = tf.feature_column.numeric_column('Triceps')
insulin = tf.feature_column.numeric_column('Insulin')

I created a loop for this as mentioned below, df_col_num is a list containing the column names for which I need to create feature column.

for col in df_col_num:
    col= tf.feature_column.categorical_column_with_hash_bucket(col,hash_bucke[enter link description here][1]t_size=50)

任何帮助或建议将不胜感激。

谢谢!

【问题讨论】:

  • stackoverflow.com/questions/46834680/…。基本上,如果您可以通过 pandas 加载数据(也可以应用过滤器),您可以遍历所有列,将每个列添加到功能列表中,而无需显式声明每个列。
  • 很高兴听到。 :D

标签: tensorflow


【解决方案1】:

您的变量是数字,但您使用的是tf.feature_column.categorical_column_with_hash_bucket,它用于分类变量。

我会使用:

variable_names = df.columns

tf_variables =[]

for index in variable_names:
    tf_variables.append(tf.feature_column.numeric_column(index)) 

这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-15
    • 2012-06-01
    • 2021-08-11
    • 2021-04-09
    • 2018-03-31
    • 2013-12-06
    • 2021-12-02
    相关资源
    最近更新 更多