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.
- 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)>>> learning_rate = 0.001>>> n_iter = 20
- Then, we define placeholders and construct the model by computing the logits (output of logistic function based on the input and model ...