Skip to content

Commit

Permalink
Product Recommendation Notebook Labified
Browse files Browse the repository at this point in the history
  • Loading branch information
daronyondem committed Jun 17, 2020
1 parent edf373e commit 2735c68
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 60 deletions.
18 changes: 16 additions & 2 deletions HOL-step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,27 @@ In this task, we will use PySpark to run a notebook on a Spark Pool.

![Import statements in the notebook are presented.](media/05-46.png)

6. Select **Run all** to run all the steps in the notebook. When the execution starts, feel free to scroll down and follow the execution step by step.
6. Select **Run all** to run all the steps in the notebook. When the execution starts, scroll down step by step and follow the execution of every cell.

!["1. Product Recommendations" notebook is open. Run all is selected.](media/product-recommendations-run-all.png)

7. Observe the results in the notebook in Cell 25.

![](media/05-47.png)
![The resulting recommendation data is shown.](media/05-47.png)

8. Scroll to the bottom of the notebook and hover over the edge of the notebook to have the **Add code** button appear. Select the **Add code** button to add a new cell into the notebook.

![At the bottom of the notebook the add code button is highlighted.](media/notebooks-product-recommendation-add-code.png)

9. Finally, copy the code below into the cell, and select **Run**. This will call the main function and pass the two parameters `user_id` and `product_id` to generate product recommendations. Observe the resulting recommendations once the execution is complete.

```python
%%pyspark
output = recommend_products(user_id=1533, num=7)
output
```

![At the bottom of the notebook the add code button is highlighted.](media/notebooks-product-recommendation.png)

### Task 4: AutoML in Azure Synapse Analytics

Expand Down
105 changes: 47 additions & 58 deletions artifacts/environment-setup/notebooks/1 Products Recommendation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 3,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -78,13 +78,13 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 66,
"execution_count": 4,
"data": {
"text/plain": "df: org.apache.spark.sql.DataFrame = [customer_id: int, product_id: int ... 3 more fields]\nres10: Array[org.apache.spark.sql.Row] = Array([84793,25,White Shoes,1,0], [43603,5,Orange SurfBoard,2,1], [33925,29,Gray with white sole shoes,3,3], [83108,25,White Shoes,2,1], [34904,19,Yellow mature Dutch cheese ,3,3], [49590,21,Cheese circle,1,0], [95886,27,Pink Shoes,1,0], [39979,2,Retro surfboard,3,3], [58533,16,Turkish Lira,2,1], [61681,17,Wood and Cork Coaster,3,3])"
"text/plain": "df: org.apache.spark.sql.DataFrame = [customer_id: int, product_id: int ... 3 more fields]\nres1: Array[org.apache.spark.sql.Row] = Array([69145,4,Brown SurfBoard,1,0], [40853,6,Blue Stripped SurfBoard,2,1], [26885,30,Brown Shoes,4,5], [72911,5,Orange SurfBoard,2,1], [16854,4,Brown SurfBoard,4,5], [59638,18,French cheese,4,5], [67347,23,Crystal Wineglass,2,1], [59638,25,White Shoes,1,0], [45041,9,Wine corkscrew,1,0], [72027,9,Wine corkscrew,2,1])"
},
"metadata": {}
}
Expand All @@ -101,15 +101,20 @@
},
{
"cell_type": "code",
"execution_count": 67,
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 67,
"data": {
"text/plain": "DataFrame[customer_id: int, product_id: int, product_name: string, total_quantity: int, rating: int]"
},
"metadata": {}
"output_type": "error",
"status": "error",
"execution_count": 5,
"data": null,
"ename": "NameError",
"evalue": "name 'df' is not defined",
"traceback": [
"NameError : name 'df' is not defined",
"Traceback (most recent call last):\n",
"NameError: name 'df' is not defined\n"
]
}
],
"metadata": {},
Expand All @@ -120,15 +125,20 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 68,
"data": {
"text/plain": "DataFrame[customer_id: int, product_id: int, product_name: string, total_quantity: int, rating: int]"
},
"metadata": {}
"output_type": "error",
"status": "error",
"execution_count": 6,
"data": null,
"ename": "NameError",
"evalue": "name 'df' is not defined",
"traceback": [
"NameError : name 'df' is not defined",
"Traceback (most recent call last):\n",
"NameError: name 'df' is not defined\n"
]
}
],
"metadata": {
Expand Down Expand Up @@ -169,11 +179,11 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 69,
"execution_count": 7,
"data": {
"text/plain": "2.4.4.dev0\nNone"
},
Expand All @@ -190,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": 70,
"execution_count": 8,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -214,7 +224,7 @@
},
{
"cell_type": "code",
"execution_count": 71,
"execution_count": 9,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -234,13 +244,13 @@
},
{
"cell_type": "code",
"execution_count": 72,
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 72,
"execution_count": 10,
"data": {
"text/plain": "customer_id product_id product_name rating\n68971 85233 22 Wineglass 5\n776197 43211 18 French cheese 3\n444660 60281 3 Blue Surf Board 1\n1392226 22685 25 White Shoes 5\n97619 5450 11 Black corkscrew 1\n1181750 69360 13 Brown Coaster 1\n1183253 400 20 Cheese chunk 5\n81326 12576 26 Black Shoes 5\n454659 45165 29 Gray with white sole shoes 3\n1410239 30297 7 Red Surfboard 0"
"text/plain": "customer_id product_id product_name rating\n301919 91046 14 Designer Coaster 0\n282477 93825 25 White Shoes 0\n476740 45057 2 Retro surfboard 0\n628434 4003 23 Crystal Wineglass 0\n1063564 66127 26 Black Shoes 5\n528349 83350 9 Wine corkscrew 0\n1083862 31288 15 Brown Cupholders 0\n966057 64628 8 Red Corkscrew 1\n431412 20860 31 Blue Shoes 3\n1088508 1411 23 Crystal Wineglass 1"
},
"metadata": {}
}
Expand Down Expand Up @@ -277,7 +287,7 @@
},
{
"cell_type": "code",
"execution_count": 73,
"execution_count": 11,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -303,11 +313,11 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 74,
"execution_count": 12,
"data": {
"text/plain": "Training model........."
},
Expand Down Expand Up @@ -338,7 +348,7 @@
},
{
"cell_type": "code",
"execution_count": 75,
"execution_count": 13,
"outputs": [],
"metadata": {},
"source": [
Expand Down Expand Up @@ -366,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": 14,
"outputs": [],
"metadata": {},
"source": [
Expand Down Expand Up @@ -411,7 +421,7 @@
},
{
"cell_type": "code",
"execution_count": 77,
"execution_count": 15,
"outputs": [],
"metadata": {},
"source": [
Expand Down Expand Up @@ -449,7 +459,7 @@
},
{
"cell_type": "code",
"execution_count": 78,
"execution_count": 16,
"outputs": [],
"metadata": {},
"source": [
Expand Down Expand Up @@ -480,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 79,
"execution_count": 17,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -504,7 +514,7 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": 18,
"outputs": [],
"metadata": {},
"source": [
Expand All @@ -515,13 +525,13 @@
},
{
"cell_type": "code",
"execution_count": 81,
"execution_count": 19,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 81,
"execution_count": 19,
"data": {
"text/plain": "userid Recommendation1 ... Recommendation4 Recommendation5\n0 18624 12 ... 5 9\n1 80704 26 ... 32 12\n2 3456 10 ... 5 31\n3 6400 12 ... 5 10\n4 24384 30 ... 10 15\n5 29696 20 ... 8 13\n6 61696 24 ... 29 4\n7 20160 24 ... 19 22\n8 59200 10 ... 16 9\n9 74816 7 ... 24 4\n10 66112 24 ... 21 4\n11 83904 10 ... 31 30\n12 33920 31 ... 3 19\n13 64960 30 ... 19 22\n14 88704 10 ... 31 30\n15 4992 12 ... 8 20\n16 79680 24 ... 4 2\n17 66368 24 ... 4 17\n18 58240 29 ... 4 6\n19 58880 12 ... 32 26\n20 62912 10 ... 12 30\n21 4224 18 ... 15 29\n22 75456 16 ... 27 22\n23 59456 24 ... 21 27\n24 64320 31 ... 3 10\n\n[25 rows x 6 columns]"
"text/plain": "userid Recommendation1 ... Recommendation4 Recommendation5\n0 18624 12 ... 5 9\n1 80704 26 ... 32 12\n2 3456 10 ... 5 31\n3 6400 12 ... 5 10\n4 24384 30 ... 10 15\n5 29696 20 ... 8 13\n6 61696 24 ... 29 4\n7 20160 24 ... 19 22\n8 59200 10 ... 16 9\n9 74816 7 ... 24 4\n10 66112 24 ... 21 4\n11 83904 10 ... 31 30\n12 33920 31 ... 3 19\n13 64960 30 ... 19 22\n14 88704 10 ... 31 30\n15 4992 12 ... 8 20\n16 79680 24 ... 4 2\n17 66368 24 ... 4 17\n18 58240 29 ... 4 6\n19 58880 12 ... 32 26\n20 62912 10 ... 12 30\n21 4224 18 ... 15 29\n22 75456 16 ... 27 22\n23 59456 24 ... 21 27\n24 64320 31 ... 3 10\n\n[25 rows x 6 columns]"
},
"metadata": {}
}
Expand Down Expand Up @@ -563,27 +573,6 @@
""
],
"attachments": {}
},
{
"cell_type": "code",
"execution_count": 82,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 82,
"data": {
"text/plain": "Recommended-Products Rating\n4 5 4.520149\n6 25 4.364865\n2 31 4.875994\n5 16 4.458258\n3 30 4.708153"
},
"metadata": {}
}
],
"metadata": {},
"source": [
"%%pyspark\n",
"output = recommend_products(user_id=1533, num=7)\n",
"output"
],
"attachments": {}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/notebooks-product-recommendation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2735c68

Please sign in to comment.