Guide to model training: Part 5 - Reliable Remarketing
Tags: mage, machinelearning, python, tutorial
Published: 2021-12-08 01:42:38

## TLDR
Got data? Build your own AI model for remarketing with machine learning!
## Outline
- Recap
- Before we begin
- What is remarketing?
- Predicting success
- Model training
- Results

## Recap
We finished all the processing of our data, so now we’ve made it to the final step of the model training series and will be training data. Based on our needs, we’ll continue with the remarketing campaign to get ready for the holiday rush! Tons of our customers will be on the lookout for holiday gifts and relevant sales, so now it’s up to us to connect them with their wishlist.

<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7rycyycy0591eozt1go.png)_We know what gifts you want (Source: [CurrentMagazine](https://www.ecurrent.com/wp-content/uploads/2019/11/HolidayGiftGuide_Splash_1219.jpg))_</center>

## Before we begin
For those following along the guide, we’re going to take the resulting data from when we scaled the numbers, categories, and imputed data. Then, we’ll be doing a merge on the data. Read our data preparation guide if you’re not familiar with joining and merging datasets.

## What is remarketing?
A lot of developers, myself included, weren’t familiar with the term remarketing. In fact, it’s often confused with or synonymously used with retargeting which is not remarketing. The core difference here is the audience. Retargeting looks for a new audience, while remarketing focuses on the old, or existing users. To define remarketing in the context of this guide, we’ll be looking at data of retired users of our product. By using the data to understand the previous users, we’ll focus our marketing campaign efforts to select individuals who will most likely come back, given a certain promo that meets their needs.

### Push notifications
The most common form of day to day remarketing you observe but rarely think about are push notifications. Everyone has a phone and you’re often reminded to open an app you haven’t opened in a while. There are also cases where apps will entice you to come back with promotions like free gifts or credits for joining.

<center>![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0l7fam7v0efu5qcg97j.png)_I’ll miss you. Come back! (Source: [quotesgram](https://cdn.quotesgram.com/img/93/42/551691791-goodbyes-are-not-forever-goodbyes-are-not-the-end-they-simply-mean-lll-miss-you-untill-we-meet-again-missing-you-quote.jpg))_</center>

### Email campaigning
In this guide, since we have a list of customer emails and email_ids, we’ll be focusing on the more traditional form of remarketing. Email campaigning is essentially the same idea, but with different mediums. We’ll be focusing on using remarketing via email to increase customer activity.

## Predicting success
The holidays are coming up, and the campaign is almost here. Everyone will be wanting to purchase luxury items such as wine or chocolates as gifts! We’ll be using machine learning to create more interaction and engagement with customers, to boost already active customers and aim to gain back inactive customers that have taken a hiatus.

### Starting data
To begin, we’ll start by combining finalized information from prior parts and putting them together. For more details on how to join data, read our [guide on combining data](https://www.mage.ai/blog/product-developers-guide-to-customizing-data-for-ai-part-1). To simplify, I’ve prepared all the datasets from our previous parts into [remarketing_campaign.csv](https://app.box.com/s/j89iapnmtddbuk68bwwvkoazpaqh8noj), which originate from these files, [categorical_campaign.csv](https://app.box.com/s/r579nozvzz79dsdnj4y5d80l9j3zplea), [numerical_campaign.csv](https://app.box.com/s/fcnlz2ooscv0xvoyjz6r93mfxqdvos20), [encoder_campaign.csv](https://app.box.com/s/f2a0a824fgin5nqyqh7w6r1s3hvqsy5e), [impute_campaign.csv](https://app.box.com/s/m25qzctbh9l63xueb3irupsmmwkmpnw7), and [datetime_campaign.csv](https://app.box.com/s/eykzgy4g2dcqoz1mieqma36or3xyaijo). This contains everything from what a customer’s household is like, purchase history, and interactions with prior campaigns.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37lfybxrqigyjf2v2yn7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tloikmuvm7uv7td9691f.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgp72hpl9434a1qlnlva.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2koniow6b0ss54iwnsj5.png)
    

### Goods and services
We’ll be offering sales on party items that make great gifts, such as wine and sweets for the holidays. Our campaign is a rerun of last year’s holiday sales. With an understanding of what’s in the campaign, we need to think about which portions of data influence a customer to action on an email campaign offering a sale on gifts. During the holidays, the sale of luxuries is hot, looking to sell wine and sweets. This is **MntWine** and **MntSweet** in our dataset.

## Model training
With the data prepared, we can begin slicing them into portions for training and testing. These sets will be used to train data using itself and determine the metrics for model evaluation in the next part.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vm8jls7w8s9z9nqvhe8.png)

### Training set
To start, we’ll identify the data we’ll want to use as our feature vector, aka input. Then we’ll determine what to look for as a result, label feature, or output. Here, we’ll use everything in our dataset, to try to predict whether they will act on another notification from us. This training set will contain the data, and confirm that the predictions will be correct.

### Test set
The test set is data that will be tested with the output from training to determine how good a model is. For our model we’ll be using the Logistic Regression function from scikit-learn.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zevkjwjldxy94eeskr48.png)

## Results
When training a classification model, we take note of the metrics at the end — accuracy, precision, recall. To learn more about what these metrics mean, check out our [guide to accuracy, precision and recall](https://www.mage.ai/blog/definitive-guide-to-accuracy-precision-recall-for-product-developers). In our next series, we’ll explore what these and more metrics are, how they’re calculated, and what their values tell us about the dataset.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6n3ttbax41tjht7nh5p.png)_Is this model good or not? We’ll find out in the next series._