09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3

6. Next we instantiate a LinearRegressor estimator; we train it using training

data using train_input_fn, and find the result for the validation dataset by

evaluating the trained model using val_input_fn:

linear_est = tf.estimator.LinearRegressor(feature_columns=feature_

columns)

linear_est.train(train_input_fn, steps=100)

result = linear_est.evaluate(val_input_fn)

7. Let's make a prediction on it:

result = linear_est.predict(val_input_fn)

for pred,exp in zip(result, y_test[:32]):

print("Predicted Value: ", pred['predictions'][0], "Expected:

", exp)

Figure 1: Generating predicted values using the LinearRegressor estimator

[ 99 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!