2016-04-21 4 views
0

folgte ich dem Tutorial logistic with theanoverwirrende Syntax mit Theano

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) 

aber ich weiß nicht, der Code "Vorhersage = p_1> 0.5". Wenn p_1> 0,5, Vorhersage = True? oder sonst?

Antwort

1

Ja, prediction = p_1 > 0.5 sagen will, ist äquivalent zu:

if p_1 > 0.5: 
    prediction = True 
else: 
    prediction = False 
+0

I „zu logisch äquivalent, aber weit besser lesbar als“ sagen würde. – Malvolio

+0

@Malvolio: nicht wahr für Anfänger, die ihre Bedeutung (noch) nicht verstehen. OPs Lesung kam zu einem kreischenden Stillstand, als er diese Frage stellen musste :) –

+0

@DanCornilescu - "lesbar" kann nicht wirklich bedeuten "lesbar für jemanden, der die Sprache noch nicht versteht". – Malvolio