You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a new Python application file named "Personalizer_quickstart.py". This application will handle both the example scenario logic and calls the Personalizer APIs.
46
+
Create a new Python application file named "personalizer_quickstart.py". This application will handle both the example scenario logic and calls the Personalizer APIs.
47
47
48
48
In the file, create variables for your resource's endpoint and subscription key.
49
49
@@ -101,11 +101,96 @@ Recall for our grocery website scenario, actions are the possible food items to
Context can represent the current state of your application, system, environment, or user. The following code creates a dictionary with user preferences, and the `get_context()` function assembles the features into a list for one particular user, which will be used later when calling the Rank API. In our grocery website scenario, the context consists of dietary preferences, a historical average of the order price, and the web browser type. Let's assume our users are always on the move and include a location context feature, which we choose randomly to simulate their travels every time `get_context()` is called.
205
+
Context can represent the current state of your application, system, environment, or user. The following code creates a dictionary with user preferences, and the `get_context()` function assembles the features into a list for one particular user, which will be used later when calling the Rank API. In our grocery website scenario, the context consists of dietary preferences, a historical average of the order price. Let's assume our users are always on the move and include a location, time of day, and application type, which we choose randomly to simulate changing contexts every time `get_context()` is called. Finally, `get_random_users()` creates a random set of 5 user names from the user profiles, which will be used to simulate Rank/Reward calls later on.
The context features in this quick-start are simplistic, however, in a real production system, designing your [features](../concepts-features.md) and [evaluating their effectiveness](../concept-feature-evaluation.md) can be non-trivial. You can refer to the aforementioned documentation for guidance
238
+
The context features in this quick-start are simplistic, however, in a real production system, designing your [features](../concepts-features.md) and [evaluating their effectiveness](../concept-feature-evaluation.md) can be non-trivial. You can refer to the aforementioned documentation for guidance
136
239
137
240
138
241
## Define a reward score based on user behavior
139
242
140
243
The reward score can be considered an indication how "good" the personalized action is. In a real production system, the reward score should be designed to align with your business objectives and KPIs. For example, your application code can be instrumented to detect a desired user behavior (for example, a purchase) that aligns with your business objective (for example, increased revenue).
141
244
142
-
In our grocery website scenario, we have three users: Bill, Satya, and Amy each with their own preferences. If a user purchases the product chosen by Personalizer, a reward score of 1.0 will be sent to the Reward API. Otherwise, the default reward of 0.0 will be used. In a real production system, determining how to design the [reward](../concept-rewards.md)can be non-trivial and may require some experimentation.
245
+
In our grocery website scenario, we have three users: Bill, Satya, and Amy each with their own preferences. If a user purchases the product chosen by Personalizer, a reward score of 1.0 will be sent to the Reward API. Otherwise, the default reward of 0.0 will be used. In a real production system, determining how to design the [reward](../concept-rewards.md) may require some experimentation.
143
246
144
247
In the code below, the users' preferences and responses to the actions is hard-coded as a series of conditional statements, and explanatory text is included in the code for demonstrative purposes. In a real scenario, Personalizer will learn user preferences from the data sent in Rank and Reward API calls. You won't define these explicitly as in the example code.
print("Bill is visiting his friend Warren in the midwest. There he's willing to spend more on food as long as it's low carb, so Bill bought"+ actionid +".")
165
268
166
-
elif (action['attributes']['price'] >10) and (context[1]['location'] !="midwest"):
269
+
elif (action['attributes']['price'] >=10) and (context[1]['location'] !="midwest"):
167
270
print("Bill didn't buy", actionid, "because the price was too high when not visting his friend Warren in the midwest.")
168
271
169
272
elif (action['dietary_attributes']['low_carb'] ==False) and (context[1]['location'] =="midwest"):
if action['dietary_attributes']['low_sodium'] ==True:
174
277
reward_score =1.0
175
-
print("Satya is health conscious, so he bought", actionid,"since it's low in sodium.")
278
+
print("Satya is health conscious, so he bought", actionid,"since it's low in sodium.")
176
279
else:
177
280
print("Satya did not buy", actionid, "because it's not low sodium.")
178
281
@@ -193,7 +296,7 @@ A Personalizer event cycle consists of [Rank](#request-the-best-action) and [Rew
193
296
194
297
### Request the best action
195
298
196
-
In a Rank call, you need to provide at least two arguments: a list of `RankActions` (_actions and their features_), and a list of (_context_) features. The response will include the `reward_action_id`, which is the ID of the action Personalizer has determined is best for the given context. The response also includes the `event_id`, which is needed in the Reward API so Personalize knows how to link the data from the Reward and Rank calls. For more information, refer to the [Rank API docs](/rest/api/personalizer/1.0/rank/rank).
299
+
In a Rank call, you need to provide at least two arguments: a list of `RankableActions` (_actions and their features_), and a list of (_context_) features. The response will include the `reward_action_id`, which is the ID of the action Personalizer has determined is best for the given context. The response also includes the `event_id`, which is needed in the Reward API so Personalize knows how to link the data from the Reward and Rank calls. For more information, refer to the [Rank API docs](/rest/api/personalizer/1.0/rank/rank).
197
300
198
301
199
302
### Send a reward
@@ -203,13 +306,13 @@ In a Reward call, you need to provide two arguments: the `event_id`, which links
203
306
204
307
### Run a Rank and Reward cycle
205
308
206
-
The following code loops through a single cycle of Rank and Reward calls for each of the three example users, then prints relevant information to the console at each step.
309
+
The following code loops through five cycles of Rank and Reward calls for a randomly selected set of example users, then prints relevant information to the console at each step.
# Quickstart: Getting started with the Personalizer client library
18
18
19
-
Imagine a scenario where a grocery e-retailer wishes to increase revenue by showing relevant and personalized products to each customer visiting their website. On the main page, there's a "Featured Product" section that displays a product to prospective customers. However, the e-retailer would like to determine how to show the right product to the right customer in order to maximize the likelihood of a purchase.
19
+
Imagine a scenario where a grocery e-retailer wishes to increase revenue by showing relevant and personalized products to each customer visiting their website. On the main page, there's a "Featured Product" section that displays a prepared meal product to prospective customers. However, the e-retailer would like to determine how to show the right product to the right customer in order to maximize the likelihood of a purchase.
20
20
21
21
In this quick-start, you'll learn how to use the Azure Personalizer service to do solve this problem in an automated, scalable, and adaptable fashion using the power of reinforcement learning. You'll learn how to create actions and their features, context features, and reward scores. You'll use the Personalizer client library to make calls to the [Rank and Reward APIs](what-is-personalizer.md#rank-and-reward-apis). You'll also run a cycle of Rank and Reward calls for three example users.
0 commit comments