Implementing logistic regression using TensorFlow

This is a bonus section where we implement logistic regression with TensorFlow and use click prediction as example. We herein use 90% of the first 300,000 samples for training, the remaining 10% for testing, and assume that X_train_enc, Y_train, X_test_enc, and Y_test contain the correct data.

  1. First, we import TensorFlow and specify parameters for the model, including 20 iterations during the training process and a learning rate of 0.001:
>>> import tensorflow as tf>>> n_features = int(X_train_enc.toarray().shape[1])>>> learning_rate = 0.001>>> n_iter = 20
  1. Then, we define placeholders and construct the model by computing the logits (output of logistic function based on the input and model ...

Get Python Machine Learning By Example - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.