Optimizing a solution for an additional objective - Amazon Personalize

Optimizing a solution for an additional objective

The primary objective of Amazon Personalize is to predict the most relevant items for your users based on historical and real-time interactions data. These are the items your users will most likely interact with (for example, the items they will most likely click). If you have an additional objective, such as maximizing streaming minutes or increasing revenue, you can create a solution that generates recommendations based on both relevance and your objective.

After you create an Interactions dataset and an Items dataset with a non-null, numerical column metadata attribute, you can create a solution that is optimized for an additional objective based on your item metadata. You can use the Amazon Personalize console, AWS Command Line Interface (AWS CLI), or AWS SDKs.

To optimize a solution for an additional objective, create a new solution with the User-Personalization recipe or Personalized-Ranking recipe and choose the numerical metadata column in your Items dataset that is related to your objective. When generating recommendations, Amazon Personalize gives more importance to items with higher values for this column of data. For example, you might choose a VIDEO_LENGTH column to maximize streaming minutes or a PRICE column to maximize revenue.

Objective requirements are as follows:

  • You can choose only one column for your objective.

  • The column must have a numerical type in your schema.

  • The column can't have a null type in your schema.

For more information about schemas and data types, see Datasets and schemas.

Balancing objective emphasis and relevance

There can be a trade-off when recommending items based more on your objective than relevance. For example, if you want to increase revenue through recommendations, recommendations for only expensive items might make items less relevant for your users and decrease user engagement and conversion.

To configure the balance between relevance and your objective, choose one of the following objective sensitivity levels when you create the solution:

  • Off: Amazon Personalize uses primarily interactions data to predict the most relevant items for your user.

  • Low: Amazon Personalize places less emphasis on your objective. Relevance through interactions data is more important.

  • Medium: Amazon Personalize places equal emphasis on your objective and relevance through interactions data.

  • High: Amazon Personalize places more emphasis on your objective. Relevance through interactions data is less important.

Measuring optimization performance

When you create a solution version (train a model) for a solution with an optimization objective, Amazon Personalize generates an average_rewards_at_k metric. The score for average_rewards_at_k tells you how well the solution version performs in achieving your objective. To calculate this metric, Amazon Personalize calculates the rewards for each user as follows:

rewards_per_user = total rewards from the user's interactions with their top 25 reward generating recommendations / total rewards from the user's interactions with recommendations

The final average_rewards_at_k is the average of all rewards_per_user normalized to be a decimal value less than or equal to 1 and greater than 0. The closer the value is to 1, the more gains on average per user you can expect from recommendations.

For example, if your objective is to maximize revenue from clicks, Amazon Personalize calculates each user score by dividing total revenue generated by the items the user clicked from their top 25 most expensive recommendations by the revenue from all of the recommended items the user clicked. Amazon Personalize then returns a normalized average of all user scores. The closer the average_rewards_at_k is to 1, the more revenue on average you can expect to gain per user from recommendations.

For more information about generating metrics, see Step 4: Evaluating a solution version with metrics.

Optimizing a solution (console)

To optimize a solution for an additional objective with the Amazon Personalize console, create a new solution and choose the column of numerical item metadata that is related to your objective.

To optimize a solution for an additional objective (console)

  1. Open the Amazon Personalize console at https://console.aws.amazon.com/personalize/home and sign in to your account.

  2. Choose the dataset group that you want to use for training.

  3. In the Create solutions section of the dashboard, choose the Start button. If you have already created a solution, choose the Create solution button.

  4. For Solution name, specify a name for the solution.

  5. For Recipe, choose either User-Personalization recipe or Personalized-Ranking recipe.

  6. In Solution configuration, if your Interactions dataset has EVENT_TYPE or both EVENT_TYPE and EVENT_VALUE columns, optionally use the Event type and Event value threshold fields to choose the interactions data that Amazon Personalize uses when training the model.

    For more information see Choosing the interactions data used for training.

  7. For Objective, choose the numerical column from the Items dataset that is related to your objective. You can choose only a numerical metadata column.

  8. For Objective sensitivity, choose the level of emphasis Amazon Personalize places on the additional objective when generating recommendations. The objective sensitivity configures how Amazon Personalize balances recommending items based on your objective versus relevance through interactions data. For more information, see Balancing objective emphasis and relevance.

  9. Configure any hyperparameter options based on your recipe and business needs. Different recipes use different hyperparameters. For available hyperparameters, see the documentation for individual recipes in Step 1: Choosing a recipe.

  10. Choose Next.

  11. On the Create solution version page, create a new solution version for the solution. For details, see Creating a solution version (console). Once you create a solution version, you can view the optimization performance in the solution version metrics. See Measuring optimization performance.

Optimizing a solution (AWS CLI)

You can optimize for an objective only with the User-Personalization or Personalized-Ranking recipe. To optimize a solution for an additional objective using the AWS CLI, create a new solution and specify your objective details using the optimizationObjective key in the solutionConfig object. The optimizationObjective has the following fields:

  • itemAttribute: Specify the name of the numerical metadata column from the Items dataset that relates to your objective.

  • objectiveSensitivity: Specify the level of emphasis that the solution places on your objective when generating recommendations. The objective sensitivity level configures how Amazon Personalize balances recommending items based on your objective versus relevance through interactions data. The objectiveSensitivity can be OFF, LOW, MEDIUM or HIGH. For more information, see Balancing objective emphasis and relevance.

The following is an example of the create-solution AWS CLI command. Replace the solution name, dataset group arn, and recipe arn values with your own.

For optimizationObjective, replace COLUMN_NAME with the numerical metadata column name from the Items dataset that is related to your objective. For objectiveSensitivity, specify OFF, LOW, MEDIUM, or HIGH.

aws personalize create-solution \ --name solution name \ --dataset-group-arn dataset group arn \ --recipe-arn recipe arn \ --solution-config "{\"optimizationObjective\":{\"itemAttribute\":\"COLUMN_NAME\",\"objectiveSensitivity\":\"MEDIUM\"}}"

When your solution is ready, create a new solution version (for an example command see Configuring a solution (AWS CLI)). Once you create a solution version, you can view the optimization performance with the solution version metrics. See Measuring optimization performance.

Optimizing a solution (AWS SDKs)

You can optimize for an objective only with the User-Personalization or Personalized-Ranking recipe.

To optimize a solution for an additional objective using the AWS SDKs, create a new solution and specify your objective details using the optimizationObjective key in the solutionConfig object for the solution. The optimizationObjective has the following fields:

  • itemAttribute: Specify the name of the numerical metadata column from the dataset group's Items dataset that relates to your objective.

  • objectiveSensitivity: Specify the level of emphasis that the solution places on your objective when generating recommendations. The objective sensitivity level configures how Amazon Personalize balances recommending items based on your objective versus relevance through interactions data. The objectiveSensitivity can be OFF, LOW, MEDIUM or HIGH. For more information, see Balancing objective emphasis and relevance.

Use the following code to create a solution with an additional objective with the AWS SDK for Python (Boto3) or the AWS SDK for Java 2.x.

When your solution is ready, create a new solution version (for example code see Creating a solution version (AWS SDKs)). Once you create a solution version, you can view the optimization performance with the solution version metrics. See Measuring optimization performance.

SDK for Python (Boto3)

To create a solution that is optimized for an additional objective, use the following create_solution method. Replace the solution name, dataset group arn, and recipe arn values with your own.

For optimizationObjective, replace COLUMN_NAME with the numerical metadata column name from the Items dataset that is related to your objective. For objectiveSensitivity, specify OFF, LOW, MEDIUM, or HIGH.

import boto3 personalize = boto3.client('personalize') create_solution_response = personalize.create_solution( name= 'solution name', recipeArn= 'recipe arn', datasetGroupArn = 'dataset group arn', solutionConfig = { "optimizationObjective": { "itemAttribute": "COLUMN_NAME", "objectiveSensitivity": "MEDIUM" } } ) solution_arn = create_solution_response['solutionArn'] print('solution_arn: ', solution_arn)
SDK for Java 2.x

To create a solution that is optimized for an additional objective, use the following createPersonalizeSolution method and pass the following as parameters: an Amazon Personalize service client, the dataset group's Amazon Resource Name (ARN), a solution name, the recipe ARN, the item attribute, and the objective sensitivity level.

public static String createPersonalizeSolution(PersonalizeClient personalizeClient, String datasetGroupArn, String solutionName, String recipeArn, String itemAttribute, String objectiveSensitivity) { try { OptimizationObjective optimizationObjective = OptimizationObjective.builder() .itemAttribute(itemAttribute) .objectiveSensitivity(objectiveSensitivity) .build(); SolutionConfig solutionConfig = SolutionConfig.builder() .optimizationObjective(optimizationObjective) .build(); CreateSolutionRequest solutionRequest = CreateSolutionRequest.builder() .name(solutionName) .datasetGroupArn(datasetGroupArn) .recipeArn(recipeArn) .solutionConfig(solutionConfig) .build(); CreateSolutionResponse solutionResponse = personalizeClient.createSolution(solutionRequest); return solutionResponse.solutionArn(); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return "";

Sample Jupyter notebook

For a sample Jupyter notebook that shows how to create a solution that is optimized for an additional objective based item metadata, see the objective_optimization folder of the Amazon Personalize samples GitHub repository