Skip to Content
Python Machine Learning By Example - Second Edition
book

Python Machine Learning By Example - Second Edition

by Yuxi (Hayden) Liu
February 2019
Beginner to intermediate
382 pages
10h 1m
English
Packt Publishing
Content preview from Python Machine Learning By Example - Second Edition

Predicting ad click-through with logistic regression using gradient descent

After a brief example, we now deploy the algorithm we just developed in our click-through prediction project.

We herein start with only 10,000 training samples (you will soon see why we don't start with 270,000, as we did in the previous chapter):

>>> import pandas as pd>>> n_rows = 300000>>> df = pd.read_csv("train", nrows=n_rows)>>> X = df.drop(['click', 'id', 'hour', 'device_id', 'device_ip'],                                                      axis=1).values>>> Y = df['click'].values>>> n_train = 10000>>> X_train = X[:n_train]>>> Y_train = Y[:n_train]>>> X_test = X[n_train:]>>> Y_test = Y[n_train:]>>> from sklearn.preprocessing import OneHotEncoder>>> enc = OneHotEncoder(handle_unknown='ignore')>>> X_train_enc ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Machine Learning by Example - Third Edition

Python Machine Learning by Example - Third Edition

Yuxi (Hayden) Liu
Python Machine Learning, Second Edition - Second Edition

Python Machine Learning, Second Edition - Second Edition

Sebastian Raschka, Jared Huffman, Vahid Mirjalili, Ryan Sun

Publisher Resources

ISBN: 9781789616729Supplemental Content