Get started (AWS SDK for Python) - Amazon Fraud Detector

Get started (AWS SDK for Python)

This topic explains how to get started programming Amazon Fraud Detector with the AWS SDK for Python (Boto3). For instruction on completing this exercise using the AWS Console, see Get started (console).

Prerequisites

The following are prerequisite steps for using the Python examples in this guide. Ensure you are using the Boto3 SDK version 1.14.29 or higher.

Step 1: Setup and verify your Python environment

Boto is the Amazon Web Services (AWS) SDK for Python. It enables Python developers to create, configure, and manage AWS services. For details on how to install Boto3, refer to the AWS SDK for Python (Boto3).

After installing, run the following Python example to confirm that your environment is configured correctly. If your environment is configured correctly, the response will contain a list of detectors. If no detectors have been created, the list will be empty.

import boto3 fraudDetector = boto3.client('frauddetector') response = fraudDetector.get_detectors() print(response)

Step 2: Create variables, entity type, and labels

After you verify that your Python environment is configured correctly, create the component resources that will be used in your events, models, and rules.

  1. Create variables. A variable is a data element that can be used in models and rules. For a code sample, see Create a variable.

  2. Create an entity type. An entity type classifies who is performing the event, such as a customer or a merchant. For a code sample, see Create an entity type.

  3. Create labels. Labels are used to classify events as either fraudulent or legitimate. For a code sample, see Create a label.

Step 3: Create event type

After you have created your component resources, you can create an event type. With Amazon Fraud Detector, you generate fraud predictions for events. An event type defines the structure for an individual event sent to Amazon Fraud Detector. Once defined, you can build models and detectors that evaluate the risk for specific event types. For a code sample, see Create event dataset Create event types.

Step 4: Create and train a model

Amazon Fraud Detector models learn to detect fraud for a specific event type. In Amazon Fraud Detector, you first create a model, which acts as a container for your model versions. Each time you train a model, a new version is created. For a code sample, see Build a model.

The example code trains an Online Fraud Insights model using data stored in Amazon S3. Online Fraud Insights is a supervised machine learning model that can be adapted to detect a variety of online fraud and abuse risks such as new account fraud, online transaction fraud, and fraudulent reviews.

Once model training is complete, you can review model performance in the AWS Console or programmatically by calling the DescribeModelVersions API. To learn more, refer to Model performance metrics.

After reviewing the model performance, activate the model to make it available for use by detectors in real-time fraud predictions. For a code sample, see Build a model.

Step 5: Create a detector, outcome, rules, and detector version

A detector contains the detection logic, such as the models and rules, for a particular event that you want to evaluate for fraud. During a fraud prediction, you will specify the detector that you want to use to evaluate your event. To create a detector, complete the following steps.

  1. Create a detector. A detector acts as a container for your detector versions. For a code sample, Create a detector.

  2. Create outcomes. An outcome is the result of a fraud prediction. For example, you may want outcomes to represent risk levels (high_risk, medium_risk, and low_risk). For a code sample, see Create an outcome.

  3. Create rules. A rule is a condition that tells Amazon Fraud Detector how to interpret variable values during a fraud prediction. A rule consists of one or more variables, a logic expression, and one or more outcomes. For a code sample, see Create a rule.

  4. Create a detector version. A detector version defines the specific models and rules that will be run as part of a fraud prediction. For a code sample, see Create a detector version.

Step 6: Generate fraud predictions

To get fraud predictions, call the GetEventPrediction API or the CreateBatchPredictionJob API. Supply information about the event you want to evaluate and synchronously receive a model score and outcome based on the designated detector. For a code sample, see Get fraud predictions.

(Optional) Explore the Amazon Fraud Detector APIs with a Jupyter (iPython) Notebook

For additional examples on how to use the Amazon Fraud Detector APIs, refer to the aws-fraud-detector-samples GitHub repository. Topics covered by the notebooks include building models and detectors using the Amazon Fraud Detector APIs and making batch fraud prediction requests using the GetEventPrediction API.