How it works...

In this recipe, we implemented a DNN regressor using a pre-made estimator; the preceding program can be divided into a variety of subparts, as follows:

  • Define the feature columns: In step 1, we created a vector of strings, which contains the names of our numeric feature columns. Next, we called the feature_columns() function, which defines the expected shape value of an input tensor and how features should be transformed (numeric or categorical) while they're being modeled. In our case, the shape of the input tensor was 784, and all the values of the input tensor were numerical. We transform the numeric features by providing the names of the numeric columns to the column_numeric() function within feature_columns(). If you have categorical columns in your data that have values such as category_x, category_y and you want to assign integer values (0, 1) to these, you can do this using the column_categorical_with_identity() function.
  • Write the dataset import functions: In step 2, we defined how a pre-made estimator receives data. It is defined by the input_fn() function. It converts raw data sources into tensors and selects feature and response columns. It also configures how data is drawn during training; that is, shuffling, batch size, epochs, and so on.
  • Instantiate the relevant pre-made Estimator: In step 3, we instantiated a pre-made deep neural network (DNN) estimator by calling dnn_regressor(). The hidden_units argument value of the function defines our network; that is, the hidden layers in the network and the number of perceptrons in each layer. It consists of dense, feedforward neural network layers. It takes vectors of integers as the argument value. In our model, we had three layers with 5, 10, and 8 perceptrons, respectively. We used relu as our activation function. The label_dimension argument of the dnn_regrssor function defines the shape of the regression target per example.
  • Call a training, evaluation method: In step 4, we trained our model, and in the next step, we predicted the values for the test dataset and evaluated the performance of the model.
..................Content has been hidden....................

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