首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >theano令人费解的语法

theano令人费解的语法
EN

Stack Overflow用户
提问于 2016-04-22 07:46:00
回答 1查看 31关注 0票数 0

我遵循了教程logistic with theano

代码语言:javascript
复制
import numpy
import theano
import theano.tensor as T
rng = numpy.random

N = 400                                   # training sample size
feats = 784                               # number of input variables



# initialize the bias term
b = theano.shared(0., name="b")

print("Initial model:")
print(w.get_value())
print(b.get_value())

# Construct Theano expression graph
p_1 = 1 / (1 + T.exp(-T.dot(x, w) - b))   # Probability that target = 1
prediction = p_1 > 0.5                    # The prediction thresholded
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum()# The cost to minimize
gw, gb = T.grad(cost, [w, b])             # Compute the gradient of the cost
                                      # w.r.t weight vector w and
                                      # bias term b
                                      # (we shall return to this in a
                                      # following section of this tutorial)

但我不知道代码“预测= p_1 > 0.5”。当p_1 >0.5时,预测=真?不然呢?

EN

回答 1

Stack Overflow用户

发布于 2016-04-22 07:53:43

是的,说prediction = p_1 > 0.5相当于:

代码语言:javascript
复制
if p_1 > 0.5:
    prediction = True
else:
    prediction = False
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36782324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档