Skip to content

Latest commit

 

History

History
 
 

targeted-marketing-python

Targeted Marketing with Amazon Machine Learning

These examples show how to identify potential customers for targeted marketing campaigns, using a publicly available banking and marketing dataset from the University of California at Irvine (UCI) repository. This dataset contains information about customers as well as descriptions of their behavior in response to previous marketing contacts. You use this data to identify which customers are most likely to subscribe to a new product. In the sample dataset, the product is a bank term deposit. A bank term deposit is a deposit made into a bank with a fixed interest rate that cannot be withdrawn for a certain period of time, also known as a certificate of deposit (CD).

This code sample demonstrates how to use the Python SDK to build and use the ML Model described in the Getting Started tutorial.

Setting up

Configuring credentials

By default, the SDK will look for a credentials file at ~/.aws/credentials or C:\Users\USER_NAME\.aws\credentials for Windows users. The file should look like this (without spaces at the beginning of each line):

[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY

Sample code

There are two main scripts that follow the "banking" example in the main documentation, but using the API instead of the web console.

The first script creates data sources, an ML model, and an evaluation object. This does everything needed to begin getting ready to make predictions, and outputs the identifiers for all of the objects created. It can be run as follows:

python build_model.py "Trying the sample code"

The second script sets the score threshold, and kicks off a batch prediction job, which uses the ML Model to generate predictions on new data. This script needs the id of the ML Model generated by the first script, which will be output at the end of the script's run. But the command will be invoked like:

python use_model.py ml-12345678901 0.77 s3://your-bucket/ml-output/

Of course, substituting "your-bucket" with the name of your own s3 bucket, which has been configured to allow AML write access, and whatever S3 prefix you like.

Note, the threshold 0.77 isn't special. We're just using it as an example. You can figure out a good threshold for your application by using the AWS console and viewing the ML Model's evaluation to "Explore Performance".