Building a regression model
Since we've explored placeholders and variables, let's build an example model for regression analysis, similar to the one we created in Chapter 13, Parallelizing Neural Network Training with TensorFlow, where our goal is to implement a linear regression model: .
In this model, w and b are the two parameters of this simple regression model that need to be defined as variables. Note that x is the input to the model, which we can define as a placeholder. Furthermore, recall that for training this model, we need to formulate a cost function. Here, we use the Mean Squared Error (MSE) cost function that we defined in Chapter 10, Predicting Continuous Target Variables with Regression Analysis .
Here, y is the true value, which is given as the input to this model for training. Therefore, we need to define y as a placeholder as well. Finally, is the prediction output, which will be computed using TensorFlow operations—tf.matmul
and tf.add
. Recall that...