Overview of machine learning models

Predicting CTR with Machine Learning in Python

Kevin Huo

Instructor

Logistic regression

Example of Logistic Regression with red and blue dots

  • Logistic regression: linear classifier between dependent variable and independent variables
Predicting CTR with Machine Learning in Python

Training the model

  • Can create the model via: clf = LogisticRegression()
  • Each classifier has a fit() method which takes in an X_train, y_train: clf.fit(X_train, y_train)
  • X_train is the vector of training features, y_train is the vector of training targets
  • Classifier should only see training data to avoid "seeing answers beforehand"
Predicting CTR with Machine Learning in Python

Testing the model

  • Each classifier has a predict() method which takes in an X_test to generate a y_test as follows:
    array([0, 1, 1, ..., 1, 0, 1])
    
  • predict_proba() method produces probability scores
    array([0.2, 0.8], [0.4, 0.6] ..., [0.1, 0.9] [0.3, 0.7]])
    
  • Score reflects probability of a particular ad being clicked by particular user
Predicting CTR with Machine Learning in Python

Evaluating the model

  • Accuracy: the percentage of test targets correctly identified
  • accuracy_score(y_test, y_pred)
  • Should not be the only metric to evaluate model, particularly in imbalanced datasets
  • CTR prediction is an example where classes are imbalanced
Predicting CTR with Machine Learning in Python

Let's practice!

Predicting CTR with Machine Learning in Python

Preparing Video For Download...