Set model weights and bias

Much like linear regression, we need a shared variable weight matrix for logistic regression. We initialize both W and b as tensors full of zeros. Since we are going to learn W and b, their initial value doesn't matter too much. These variables are the objects that define the structure of our regression model, and we can save them after they've been trained so that we can reuse them later.

We define two TensorFlow variables as our parameters. These variables will hold the weights and biases of our logistic regression and they will be continually updated during training.

Notice that W has a shape of [4, 3] because we want to multiply the 4-dimensional input vectors by it to produce 3-dimensional vectors of evidence for the difference classes. b has a shape of [3], so we can add it to the output. Moreover, unlike our placeholders (which are essentially empty shells waiting to be fed data), TensorFlow variables need to be initialized with values, say, with zeros:

#Randomly sample from a normal distribution with standard deviation .01

weights = tf.Variable(tf.random_normal([num_explanatory_features,num_target_values],
mean=0,
stddev=0.01,
name="weights"))

biases = tf.Variable(tf.random_normal([1,num_target_values],
mean=0,
stddev=0.01,
name="biases"))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset