Creating many feature columns in Tensorflow

前端 未结 3 956
轻奢々
轻奢々 2021-01-04 03:42

I\'m getting started on a Tensorflow project, and am in the middle of defining and creating my feature columns. However, I have hundreds and hundreds of features- it\'s a pr

3条回答
  •  时光取名叫无心
    2021-01-04 04:37

    What you have posted in the question makes sense. Small extension based on your own code:

    import pandas.api.types as ptypes
    my_columns = []
    for col in df.columns:
      if ptypes.is_string_dtype(df[col]): 
        my_columns.append(tf.feature_column.categorical_column_with_hash_bucket(col, 
            hash_bucket_size= len(df[col].unique())))
    
      elif ptypes.is_numeric_dtype(df[col]): 
        my_columns.append(tf.feature_column.numeric_column(col))
    
      elif ptypes.is_categorical_dtype(df[col]): 
        my_columns.append(tf.feature_column.categorical_column(col, 
            hash_bucket_size= len(df[col].unique())))
    

提交回复
热议问题