【问题标题】:linear model in tensor flow张量流中的线性模型
【发布时间】:2017-09-26 12:21:42
【问题描述】:

我试图在 Tensorflow 中生成一个简单的线性模型。这是代码...

N        = 400
features = 100
nSteps   = 1000

data = (np.random.randn(N, features), np.random.randint(0, 2, N))

W = tf.placeholder(tf.float32, shape=(features,1), name='W')
b = tf.placeholder(tf.float32, shape=(features,1), name='b')
d = tf.constant(data[0], dtype=tf.float32)

result = tf.add( tf.matmul(d, W), b)

原来b的尺寸可能有问题,但由于某种原因,据我所知,它们都还可以......

不确定为什么会引发错误。有人可以帮忙吗?

注意:

result = tf.matmul(d, W)

没关系。

我检查了结果的形状,和b的形状一样。不太确定可能是什么问题。

【问题讨论】:

    标签: python tensorflow linear-algebra


    【解决方案1】:

    在线性模型中(即输出层中的一个单元),b 应该是一个标量。

    从数学上讲,对于单个观察,您有:result = WX + b,其中维度 W [1 x 特征],X [特征 x 1]。然后,WX 是标量。因此b 应该是一个标量。

    因此,您应该将b 更改为以下内容,以获得正确的线性模型并计算出尺寸:

    b = tf.placeholder(tf.float32, shape=(1,1), name='b')
    

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      相关资源
      最近更新 更多