我是 tensorflow 新手。我有一个包含连续值、离散值和分类值的数据集。样本数据如下:
col1 col2 col3 col4 col5 col6 Class
0 22 23.40 45.60 11 1.0 0.0 0.0
1 346 67.40 235.60 23 1.0 1.0 0.0
2 22 67.34 364.66 17 0.0 0.0 1.0
3 1231 124.44 213.89 14 1.0 0.0 1.0
col1 和 col4 是离散变量。 col2 和 col3 是连续变量。 col5 和 col6 是分类变量。 类是目标变量。
我想知道是否可以将上述数据直接作为占位符X
的输入传递。
X = tf.placeholder(tf.float32, [None, numFeatures])
我不必应用tf.one_hot
,对吗?因为我的分类变量是二进制的。
tensorflow如何检测col5和col6是分类变量?
如有任何帮助,我们将不胜感激。谢谢!
最佳答案
由于您的变量是二进制的,因此可以将它们视为 int
您必须创建占位符,稍后将在训练部分通过传递批处理来使用这些占位符。
以下是如何声明 tensorflow 占位符,以便它们具有正确的数据类型。
var1 = tf.placeholder(tf.int32, shape)
var4 = tf.placeholder(tf.int32, shape)
var2 = tf.placeholder(tf.float32, shape)
var3 = tf.placeholder(tf.float32, shape)
var5 = tf.placeholder(tf.int32, shape)
var6 = tf.placeholder(tf.int32, shape)
class_ = tf.placeholder(tf.int32, shape)
为了将变量集提供给模型,您稍后必须将它们连接起来,但在此之前您应该转换张量以使所有变量都处于相同的数据类型中以进行连接。
var1 = tf.cast(var1, tf.float32)
...
data = tf.concat([var1,var4, var2,var3, var5, var6], axis=1)
关于python - 如何混合分类、离散和连续数据作为 tensorflow 的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44956591/