Personalizer - Prepare the Dataset and User Profile Method

Learn to build a recommendation system using the Azure Personalizer SDK for Python.

Introduction

In this lesson, we’re going to build a recommendation system that will recommend different types of drinks to a user based on their actions and behaviors with the application. We’ll consider five different types of drinks to build the system.

Dependency

To work with the lessons in this chapter, the following python package dependency is required:

  • azure-cognitiveservices-personalizer

To know how to install these dependencies, refer to the Appendix section.

Implementation

To implement the personalizer service, we need to follow the below steps:

  • Step 1: We need to prepare the dataset. This data will contain the item/product that we want to recommend and the features of that product.
  • Step 2: We need to create actions using the RankableAction class. This class will ensure that the personalizer service can rank the action items.
  • Step 3: We need to get the user profile information. This information can consist of the user’s age, interests, user’s mood, etc.
  • Step 4: We need to build the personalizer loop that will help the personalizer model to understand the user’s behavior and suggests the actions accordingly. We also need to implement the Rank and Reward API calls to make sure that the personalizer service is able to get a reward based on each action item suggested.

Let’s start the implementation in a step-by-step manner.

Preparing the dataset

First, let’s prepare the dataset. In this chapter, we’ll use five different types of drinks—coffee, latte, tea, water, and smoothie. We’ll also need to define the features for each of the drinks. We will define the following features:

  • calorie_level: The value range from 0 to 5 denoting the calorie value present in the drink. A value of 0 will denote very low or no-calorie and a value of 5 will denote a high-calorie drink.
  • caffeine_level: The value range from 0 to 5 denoting the caffeine value present in the drink. A value of 0 will denote very low or no caffeine and a value of 5 will denote a high-caffeine drink.
  • type: The type of the drink. It can have only two values i.e., hot or cold.

Let’s see the dataset in the below code block.

Get hands-on with 1200+ tech skills courses.