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.
Cet exercice fait partie du cours
Introduction to TensorFlow in Python
Instructions
- Complete the feature column for
bedroomsand add another numeric feature column forbathrooms. Usebedroomsandbathroomsas the keys. - Create a list of the feature columns,
feature_list, in the order in which they were defined. - Set
labelsto be equal to thepricecolumn inhousing. - Complete the
bedroomsentry of thefeaturesdictionary and add another entry forbathrooms.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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