Apache Spark Deep Learning Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

This section explains how the cost function is used to generate weights and bias.

  1. A for loop will be implemented that will perform gradient descent on the weights and bias to tweak the values until the cost function gets close to 0.
  2. The loop will iterate over the cost function 100,000 times. Each time, a random value for height and weight from the 29 individuals is selected.
  3.  A summation value, z, is calculated from the random height and weight, and the input is used to calculate a predictedGender score with the sigmoid function.
  4. The cost function is calculated and added to a list that tracks all cost functions through the 100,000 iterations, allCosts.
  5. A series of partial derivatives is calculated with respect to the summation value (z) as well as the cost function (cost).
  6. These calculations are ultimately used to update the weights and bias with respect to the cost function until they (w1, w2, and b) return a value that is close to 0 for the cost function over the 100,000 iterations.
  7. Ultimately, the goal is for the values to be decreasing for the cost function as the iterations increase.  The output of the cost function values over the 100,000 iterations can be seen in the following screenshot:
  1. Over the course of the iterations, the cost value dropped from ~0.45 to ~0.01.
  2. Additionally, we can view the final output for the values of w1, w2, and b that produced the lowest value of the cost function as seen in the following screenshot: