1

I have multiple feature columns in TensorFlow and I am trying to create the loop to avoid manual typing to create feature column but its not working. Below is the list of all the columns which I need to create feature columns(this is just a dummy data, but what if we have hundreds of columns).

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)

Any help or suggestions would be appreciated.

Thanks !

2
  • 1
    see stackoverflow.com/questions/46834680/…. Basically if you can load your data through pandas (also you can apply filters too), you iterate through all columns, adding each to the list of features, without the need to declare each of them explicitly. Commented Nov 21, 2017 at 1:38
  • glad to hear. :D Commented Dec 10, 2017 at 4:54

1 Answer 1

3

your variables are numeric, but you are using tf.feature_column.categorical_column_with_hash_bucket, which is for categorical variables.

I'd use:

variable_names = df.columns

tf_variables =[]

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

This worked for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.