Preparing to train with Estimators
For this exercise, we'll return to the King County housing transaction dataset from chapter 2. We will again develop and train a machine learning model to predict house prices; however, this time, we'll do it using the estimator
API.
Rather than completing everything in one step, we'll break this procedure down into parts. We'll begin by defining the feature columns and loading the data. In the next exercise, we'll define and train a premade estimator
. Note that feature_column
has been imported for you from tensorflow
. Additionally, numpy
has been imported as np
, and the Kings County housing dataset is available as a pandas
DataFrame
: housing
.
This exercise is part of the course
Introduction to TensorFlow in Python
Exercise instructions
- Complete the feature column for
bedrooms
and add another numeric feature column forbathrooms
. Usebedrooms
andbathrooms
as the keys. - Create a list of the feature columns,
feature_list
, in the order in which they were defined. - Set
labels
to be equal to theprice
column inhousing
. - Complete the
bedrooms
entry of thefeatures
dictionary and add another entry forbathrooms
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define feature columns for bedrooms and bathrooms
bedrooms = feature_column.numeric_column("____")
bathrooms = ____
# Define the list of feature columns
feature_list = [____, ____]
def input_fn():
# Define the labels
labels = np.array(____)
# Define the features
features = {'bedrooms':np.array(housing['____']),
'bathrooms':____}
return features, labels