vDataFrame.recommend

In [ ]:
vDataFrame.recommend(unique_id: str,
                     item_id: str,
                     method: str = "count",
                     rating: (str, tuple) = "",
                     ts: str = "",
                     start_date: (str, datetime.datetime, datetime.date, float,) = "",
                     end_date: (str, datetime.datetime, datetime.date, float,) = "",)

Recommends items based on the collaborative filtering (CF) technique. The implementation of this function is the identical to that of the APRIORI algorithm, but is limited to pairs of items.

Parameters

Name Type Optional Description
unique_id
str
❌
Input vcolumn corresponding to a unique ID. It is a primary key.
item_id
str
❌
Input vcolumn corresponding to an item ID. It is a secondary key used to compute the different pairs.
method
str
✓
Method used to recommend.
  • count : Each item will be recommended based on frequencies of the different items pair.
  • avg : Each item will be recommended based on the average rating of the different items pair second element.
  • median : Each item will be recommended based on the median rating of the different items pair second element.
rating
str / tuple
✓
Input vcolumn including the items rating. If the 'rating' type is 'tuple', it must composed of 3 elements: r_vdf, r_item_id, r_name) where:
  • r_vdf is an input vDataFrame.
  • r_item_id is an input vcolumn which must includes the same id as 'item_id'.
  • r_name is an input vcolumn including the items rating.
ts
str
✓
TS (Time Series) vcolumn to use to order the data. The vcolumn type must be date like (date, datetime, timestamp...) or numerical.
start_date
str / date / float
✓
Input Start Date. For example, time = '03-11-1993' will filter the data when 'ts' is lesser than November 1993 the 3rd.
end_date
str / date / float
✓
Input End Date. For example, time = '03-11-1993' will filter the data when 'ts' is greater than November 1993 the 3rd.

Returns

vDataFrame : The vDataFrame of the recommendation.

Example

In [53]:
from verticapy import vDataFrame
order_items = vDataFrame("olist.order_items")
order_reviews = vDataFrame("olist.order_reviews")
products = vDataFrame("olist.products")
product_category_name_translation = vDataFrame("olist.product_category_name_translation")
# Orders
display(order_items)
# Reviews
display(order_reviews)
# Products
display(products)
# Products Name Translation
display(product_category_name_translation)
123
Uuid
123
order_item_id
Int
123
Uuid
123
Uuid
📅
shipping_limit_date
Timestamp
123
price
Numeric(9,3)
123
freight_value
Numeric(8,3)
112017-09-19 09:45:3558.913.29
212017-05-03 11:05:13239.919.93
312018-01-18 14:48:30199.017.87
412018-08-15 10:10:1812.9912.79
512017-02-13 13:57:51199.918.14
612017-05-23 03:55:2721.912.69
712017-12-14 12:10:3119.911.85
812018-07-10 12:30:45810.070.75
912018-03-26 18:31:29145.9511.65
1012018-07-06 14:10:5653.9911.4
1112018-03-29 22:28:0959.998.88
1212018-07-31 17:30:3945.012.98
1312018-07-26 17:24:2074.023.32
1412018-02-21 02:55:5249.913.37
1522018-02-21 02:55:5249.913.37
1612018-08-17 12:15:1099.927.65
1712018-05-02 09:31:53639.011.34
1812018-05-16 20:57:03144.08.77
1912017-08-21 03:33:1399.013.71
2012018-02-28 12:08:3725.016.11
2112018-03-29 20:07:4947.98.88
2212017-11-27 19:09:0221.9911.85
2312018-03-21 11:10:11119.9944.4
2412018-03-05 09:35:4149.015.1
2512017-09-15 18:04:3748.916.6
2612017-08-11 00:35:12219.916.98
2712018-01-29 21:51:25289.026.33
2812017-03-29 13:05:42109.925.51
2912018-06-14 05:16:2427.97.94
3012017-12-13 03:16:36119.917.32
3112017-11-30 06:30:55397.024.65
3212018-04-12 19:08:2859.923.35
3312017-10-20 16:07:5221.3315.1
3422017-10-20 16:07:5221.3315.1
3532017-10-20 16:07:5221.3315.1
3612017-05-29 03:15:2416.514.1
3712018-01-18 09:11:2421.915.1
3812018-01-23 03:35:4739.016.11
3912017-05-05 10:05:1249.7520.8
4012017-04-24 22:25:19809.144.29
4112018-02-13 19:10:3799.9913.72
4212018-03-12 06:50:2659.919.95
4312018-01-04 02:33:4224.8917.63
4422018-01-04 02:33:4224.8917.63
4532018-01-04 02:33:4224.8917.63
4612018-07-10 02:51:1054.08.54
4712018-04-02 17:50:1781.9913.01
4812017-11-29 22:38:4799.013.71
4912017-05-18 17:35:1118.997.78
5022017-05-18 17:35:1118.997.78
5112017-05-25 02:15:2038.3316.79
5212017-02-01 13:17:5769.918.0
5312017-03-23 11:47:37195.018.21
5412018-05-22 10:59:5035.915.2
5512017-12-04 09:58:0779.521.05
5612017-08-21 03:03:4429.9915.1
5712018-04-26 12:30:57109.913.21
5812018-04-10 16:50:1174.916.49
5912018-04-02 16:35:2014.9518.23
6012018-05-14 22:14:46149.943.11
6112018-01-03 17:59:3519.9914.1
6212018-07-10 09:30:09390.029.39
6312018-03-07 02:49:09135.021.75
6412017-02-06 21:18:03104.016.43
6512017-11-10 21:26:45149.015.8
6612017-12-04 03:32:47279.913.46
6712018-02-27 11:55:5744.923.22
6812018-07-26 17:44:3637.9919.18
6912018-08-21 03:35:1729.9915.31
7012017-12-22 15:51:31120.015.59
7112018-09-03 03:50:23492.7521.62
7212018-05-08 12:14:5294.918.54
7312018-02-22 19:46:5088.3421.11
7412017-06-26 22:10:14199.9965.56
7512018-03-15 10:35:3799.919.67
7612018-05-21 17:32:0378.08.9
7722018-05-21 17:32:0378.08.9
7812017-11-27 03:47:23155.014.84
7912018-07-04 17:11:12249.934.23
8012018-03-27 13:15:2753.9823.31
8112017-08-10 09:30:158.9932.57
8222017-08-10 09:30:1544.97.16
8312017-11-29 23:13:3860.617.67
8412018-04-06 17:10:21225.067.24
8512018-08-17 15:04:2539.915.38
8612018-04-17 09:12:1176.034.07
8712018-03-15 19:28:51159.027.19
8812017-05-24 19:22:34102.914.45
8922017-05-24 19:22:34102.914.45
9012017-07-28 03:45:2663.916.89
9112018-05-02 22:10:29168.88.21
9212017-09-29 17:50:1659.99.94
9322017-09-29 17:50:1659.99.94
9412018-07-18 04:25:09232.7528.58
9512018-08-23 15:11:4048.918.44
9612017-08-23 01:25:3987.012.11
9712017-12-12 01:29:45131.918.54
9812018-02-27 03:31:0819.914.1
9912018-08-08 15:10:11136.9966.04
10012017-10-19 01:07:30399.9923.64
Rows: 1-100 | Columns: 7
123
Uuid
123
Uuid
123
review_score
Int
Abc
review_comment_title
Varchar(70)
Abc
Varchar(538)
📅
review_creation_date
Timestamp
📅
review_answer_timestamp
Timestamp
15[null]2018-03-20 00:00:002018-03-20 18:36:04
25[null]2018-06-22 00:00:002018-06-26 13:51:29
35Entrega rápida!2018-04-25 00:00:002018-04-26 14:55:36
45[null]2017-05-30 00:00:002017-06-01 23:28:55
55[null]2017-08-12 00:00:002017-08-13 19:56:53
65[null]2018-02-06 00:00:002018-02-06 20:54:37
71[null]2018-05-24 00:00:002018-05-24 12:45:38
85SUPER RECOMENDO2018-07-01 00:00:002018-07-02 12:32:24
95[null]2017-09-01 00:00:002017-09-02 13:04:08
105[null]2017-11-25 00:00:002017-11-27 11:37:22
115[null]2017-06-20 00:00:002017-06-22 23:19:41
125[null]2017-10-15 01:00:002017-10-15 17:53:22
135[null]2017-11-15 00:00:002017-11-18 02:22:01
145Bom2018-06-19 00:00:002018-06-20 04:48:13
155[null]2017-08-26 00:00:002017-08-30 12:03:31
165[null]2018-06-14 00:00:002018-06-16 19:15:24
174[null]2017-04-06 00:00:002017-04-07 18:00:25
185[null]2017-08-03 00:00:002017-08-05 23:47:13
191[null]2018-03-25 00:00:002018-03-26 11:38:15
204[null]2017-07-26 00:00:002017-07-26 23:31:23
215[null]2018-01-18 00:00:002018-01-19 01:51:32
225[null]2018-06-13 00:00:002018-06-14 00:24:36
234[null]2018-03-26 00:00:002018-04-02 14:03:42
245[null]2018-04-14 00:00:002018-04-16 23:11:12
254[null]2017-05-17 00:00:002017-05-18 11:39:45
265[null]2017-06-03 00:00:002017-06-07 04:00:21
274[null]2017-05-30 00:00:002017-05-30 23:08:24
284[null]2018-08-12 00:00:002018-08-14 11:35:39
293[null]2017-11-14 00:00:002017-11-16 19:23:19
303[null]2017-12-22 00:00:002017-12-22 23:49:40
314[null]2018-08-24 00:00:002018-08-24 11:56:51
325ENTREGA DENTRO DO PRAZO2018-05-16 00:00:002018-05-25 17:57:16
334[null]2018-03-13 00:00:002018-03-13 20:34:04
343[null]2018-06-15 00:00:002018-06-15 19:20:57
355[null]2018-04-27 00:00:002018-04-28 02:28:01
365[null]2017-09-27 00:00:002017-09-27 23:54:04
374[null]2017-12-20 00:00:002017-12-22 22:25:40
384[null]2017-02-14 00:00:002017-02-15 14:28:07
395[null]2018-03-15 00:00:002018-03-16 11:18:48
405[null]2018-07-21 00:00:002018-07-24 11:57:27
414[null]2017-08-01 00:00:002017-08-04 11:08:08
425[null]2018-06-22 00:00:002018-06-25 14:30:21
435[null]2017-11-25 00:00:002017-11-26 13:21:30
445Recomendo 2018-04-28 00:00:002018-04-30 23:48:44
455[null]2017-07-15 00:00:002017-07-16 16:33:50
461[null]2018-05-01 00:00:002018-05-01 21:25:23
475[null]2017-06-09 00:00:002017-06-12 19:36:32
485[null]2017-04-20 00:00:002017-04-26 10:44:16
492[null]2018-04-21 00:00:002018-04-21 17:05:31
504[null]2018-07-06 00:00:002018-07-09 15:03:17
512[null]2017-11-29 00:00:002017-11-29 09:31:07
524[null]2017-11-09 00:00:002017-11-10 20:22:03
535[null]2017-11-09 00:00:002017-11-09 14:45:42
544[null]2018-02-06 00:00:002018-02-07 12:04:30
554[null]2018-04-11 00:00:002018-04-11 11:09:23
565recomendo2018-07-10 00:00:002018-07-11 11:29:17
574[null]2018-02-03 00:00:002018-02-05 23:58:28
585[null]2017-03-07 00:00:002017-03-08 08:49:45
595[null]2017-01-13 00:00:002017-01-14 11:20:25
605[null]2018-06-14 00:00:002018-06-17 23:58:20
614[null]2018-06-13 00:00:002018-06-14 16:41:13
622[null]2017-05-21 00:00:002017-05-21 23:49:03
635[null]2017-03-12 00:00:002017-03-13 20:56:20
645[null]2017-10-08 00:00:002017-10-10 02:03:18
655[null]2018-01-05 00:00:002018-01-06 21:46:11
662[null]2018-01-13 00:00:002018-01-17 13:19:36
675[null]2017-08-22 00:00:002017-08-22 19:52:17
681[null]2017-11-22 00:00:002017-11-22 14:21:08
695super recomendado2018-05-18 00:00:002018-05-21 15:47:15
705[null]2017-11-29 00:00:002017-11-30 01:07:38
715[null]2018-03-29 00:00:002018-04-02 01:16:46
723[null]2018-05-16 00:00:002018-05-16 18:16:57
735[null]2017-11-02 00:00:002017-11-07 14:45:12
745[null]2017-03-08 00:00:002017-03-09 10:00:37
751[null]2018-03-21 00:00:002018-03-21 09:36:01
764[null]2018-02-20 00:00:002018-02-26 12:44:42
775[null]2017-10-09 00:00:002017-10-09 20:44:01
785[null]2018-05-17 00:00:002018-05-20 16:12:30
795[null]2018-02-10 00:00:002018-02-12 13:05:05
805[null]2017-06-22 00:00:002017-06-23 00:49:50
815[null]2017-12-21 00:00:002017-12-23 18:46:59
825[null]2017-03-17 00:00:002017-03-20 00:39:40
833[null]2017-05-04 00:00:002017-05-08 22:18:18
845[null]2018-03-03 00:00:002018-03-05 11:56:52
851[null]2018-07-29 00:00:002018-07-30 05:09:09
861[null]2018-08-10 00:00:002018-08-10 07:31:10
875[null]2018-05-18 00:00:002018-05-20 16:15:11
885[null]2018-05-06 00:00:002018-05-07 15:00:11
895[null]2018-05-30 00:00:002018-05-30 22:10:23
903[null]2018-04-18 00:00:002018-06-14 23:46:31
915[null]2018-04-06 00:00:002018-04-07 15:57:53
923[null]2017-05-10 00:00:002017-05-13 00:26:19
933[null]2018-03-09 00:00:002018-03-10 23:32:33
945[null]2018-08-11 00:00:002018-08-11 18:03:41
954[null]2018-08-17 00:00:002018-08-18 01:32:06
965[null]2018-07-13 00:00:002018-07-14 12:34:42
973[null]2017-02-14 00:00:002017-02-15 03:13:03
985[null]2018-08-26 00:00:002018-08-29 19:11:50
995[null]2017-11-14 00:00:002017-11-16 13:25:12
1005[null]2017-12-08 00:00:002017-12-10 19:07:17
Rows: 1-100 | Columns: 7
123
Uuid
Abc
Varchar(92)
123
product_name_lenght
Int
123
product_description_lenght
Int
123
product_photos_qty
Int
123
product_weight_g
Int
123
product_length_cm
Int
123
product_height_cm
Int
123
product_width_cm
Int
1535966300201616
25675241225551026
3502662300451535
4253643550192412
5486134250221115
6581771100161516
7422461170025515
8532741600302020
9422531600040430
1045520360026822
115038111800472141
125638936300301515
135534431850363716
14589466650251015
1553631275030535
16182631355221612
1754175032600105370
18446293600403040
19431125350453030
205912951200201111
21367073150201015
22285024800252525
23404371155026620
2459110061550161016
2553866320018513
26524202505050850
275521411000164636
285590041850451245
29557052211001002060
3043121311800302222
31511470315035225
326018833175231113
333611051380181214
34591691120400303030
35516951200201818
365031919001001112
37466471550301025
3844776210000653535
395494215016511
4033384140017720
4159302911200202020
4260382150025217
43509842246221519
4445569115016715
4559412120016211
46332232950601515
475970364550471923
48493261250202020
49376702600171522
50503292150161816
514880812800303030
525684111340321427
53[null][null][null]50024415
54585931180040830
554421612200371032
5659163142550384225
57485161690171713
58576762633191217
5959173551550402020
605925313875461243
615519711133161611
62391694450162411
635627922800503515
644814111350161616
6555373180040511
66589163700203520
67399913150202020
6845916123250502020
6957338340023715
70385811150162313
7158734325017412
72263451700161616
73[null][null][null]2100503030
74384401600223316
75593512250161616
765378641125281523
7757319225016511
785241817850286228
7927406420018712
80361241312100606020
81342491200161111
82523961900451535
835610271187171314
84585964512301218
85561832650351528
86415691350171517
8763326415016413
88475961300191015
8930253135024517
906093519050562628
9141312118550543545
92499982200161611
9352857122516414
94[null][null][null]40024415
95536461300163020
965419783400421626
9742120261550421717
9859600120019411
99596425165060833
10047816230016512
Rows: 1-100 | Columns: 9
Abc
Varchar(92)
Abc
Varchar(78)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Rows: 1-71 | Columns: 2
In [55]:
# Recommendation based on the Frequencies

order_items.recommend("order_id",
                      "product_id",)
Out[55]:
123
Uuid
123
Uuid
123
cnt
Int
123
rank
Integer
121
222
341
422
523
621
761
821
922
1021
1122
1231
1321
1421
1521
1641
1731
1821
1921
2021
2131
2221
2361
2431
2522
2691
2731
281001
29102
3031
3121
3261
3341
3431
3521
3621
3741
3842
39161
4021
4131
4222
4323
4441
4542
4643
4731
4821
4921
5031
5132
5221
5321
5421
5591
5622
5721
5821
5921
6051
6181
6221
6321
6421
65131
6672
6773
6874
6975
7046
7127
7228
7329
7421
7522
7631
7721
7841
7922
8021
8121
8222
8321
8422
8531
8661
8731
88241
8931
9041
9122
9223
9324
9425
9526
9627
9791
9842
9921
10021
Rows: 1-100 | Columns: 4
In [54]:
# Recommendation based on the Score

vdf = order_items[["order_id", "product_id"]].join(order_reviews,
                                                   how = "left",
                                                   on = {"order_id": "order_id"},
                                                   expr2 = ["review_score"])
recommend = vdf.recommend("order_id",
                          "product_id",
                          method = "avg",
                          rating = "review_score")
recommend.join(products,
               how = "left",
               on = {"item1": "product_id"},
               expr2 = ["product_category_name AS product_category_name_1"]).join(
               products,
               how = "left",
               on = {"item2": "product_id"},
               expr2 = ["product_category_name AS product_category_name_2"]).join(
               product_category_name_translation,
               how = "left",
               on = {"product_category_name_1": "product_category_name"},
               expr2 = ["product_category_name_english AS product_category_name_english_1"]).join(
               product_category_name_translation,
               how = "left",
               on = {"product_category_name_2": "product_category_name"},
               expr2 = ["product_category_name_english AS product_category_name_english_2"])
Out[54]:
123
Uuid
123
Uuid
123
cnt
Int
123
score1
Float
123
score2
Float
123
rank
Int
Abc
Varchar(92)
Abc
Varchar(92)
Abc
product_category_name_english_1
Varchar(78)
Abc
product_category_name_english_2
Varchar(78)
124.615384615384613.678571428571431perfumeryperfumery
224.615384615384613.252perfumeryperfumery
323.54.01housewaresgarden_tools
443.51.02housewareshousewares
523.51.03housewareshousewares
624.714285714285714.21consoles_gamesconsoles_games
761.51.751cool_stuffcool_stuff
824.111111111111114.694444444444441babytoys
924.111111111111114.636363636363642babybaby
1024.016393442622954.454545454545451bed_bath_tablebed_bath_table
1124.016393442622953.590909090909092bed_bath_tablebed_bath_table
1233.416666666666673.251perfumeryperfumery
1321.751.333333333333331bed_bath_tablebed_bath_table
1423.571428571428574.333333333333331autoconstruction_tools_construction
1521.04.121739130434781housewaresbed_bath_table
1641.01.01construction_tools_safetyhome_construction
1735.05.01pet_shoppet_shop
1823.85.01bed_bath_tablebed_bath_table
1924.3753.571428571428571bed_bath_tablebed_bath_table
202[null][null]1computers_accessoriescomputers_accessories
2134.01.01stationerystationery
2225.05.01sports_leisuresports_leisure
2365.05.01office_furnitureoffice_furniture
2423.142857142857144.333333333333331bed_bath_tablebed_bath_table
2533.142857142857143.761904761904762bed_bath_tablebed_bath_table
2695.03.666666666666671cool_stuffcool_stuff
2733.6254.179487179487181stationerystationery
281001.01.01health_beautyhealth_beauty
29101.01.02health_beautyhealth_beauty
3032.04.692307692307691furniture_decorfurniture_decor
3124.03.01bed_bath_tablebed_bath_table
3264.44.526315789473681autoauto
3343.43.742857142857141watches_giftswatches_gifts
3444.714285714285714.01sports_leisurefood_drink
3534.04.095238095238091furniture_decorfurniture_decor
3621.04.29629629629631furniture_decorbed_bath_table
3723.985074626865674.555555555555561bed_bath_tablebed_bath_table
3844.04.333333333333331housewareshousewares
3944.04.02housewareshousewares
40164.555555555555564.461538461538461bed_bath_tablebed_bath_table
4123.517241379310343.523809523809521furniture_decorfurniture_decor
4223.64.01costruction_tools_gardencostruction_tools_garden
4333.63.752costruction_tools_garden[null]
4423.63.63costruction_tools_gardencostruction_tools_garden
4543.666666666666675.01bed_bath_tablebed_bath_table
4643.666666666666674.02bed_bath_tablebed_bath_table
4743.666666666666673.666666666666673bed_bath_tablebed_bath_table
4832.751.01furniture_decorhousewares
4924.54.714285714285711housewareshousewares
5024.254.01bed_bath_tablebed_bath_table
5134.095238095238094.01furniture_decorfurniture_decor
5234.095238095238093.52furniture_decorfurniture_decor
5323.857142857142864.055555555555561furniture_decorfurniture_decor
5423.428571428571433.01sports_leisuresports_leisure
5525.04.072992700729931fashion_bags_accessoriesfashion_bags_accessories
5624.243902439024394.641025641025641health_beautyhealth_beauty
5794.243902439024394.541353383458652health_beautyhealth_beauty
5824.842105263157894.81health_beautyhealth_beauty
5925.0[null]1home_constructionhome_construction
6022.363636363636363.345454545454551furniture_decoroffice_furniture
6154.205673758865253.894736842105261consoles_gamesconsoles_games
6285.05.01construction_tools_constructionconstruction_tools_construction
6325.03.945945945945951furniture_decorgarden_tools
6425.05.01health_beautyhealth_beauty
6524.333333333333334.751luggage_accessoriesluggage_accessories
6624.081818181818184.555555555555561garden_toolsbed_bath_table
6774.081818181818184.232758620689652garden_toolsgarden_tools
6874.081818181818184.139410187667563garden_toolsgarden_tools
6974.081818181818184.008522727272734garden_toolsgarden_tools
7024.081818181818184.05garden_toolshome_construction
71194.081818181818183.965957446808516garden_toolsgarden_tools
72104.081818181818183.945945945945957garden_toolsgarden_tools
7344.081818181818183.333333333333338garden_toolsbaby
7424.081818181818183.09garden_toolssports_leisure
7524.071428571428574.290322580645161watches_giftswatches_gifts
7624.071428571428574.02watches_giftswatches_gifts
7734.333333333333334.166666666666671bed_bath_tablebed_bath_table
7824.04.01housewaresfurniture_decor
7943.833333333333334.714285714285711autoauto
8023.833333333333334.376470588235292autoauto
8124.55.01[null]furniture_decor
8223.03.01construction_tools_constructionconstruction_tools_construction
8323.02.666666666666672construction_tools_constructionconstruction_tools_construction
8422.933333333333333.736842105263161babycool_stuff
8522.933333333333333.02babybaby
8635.05.01books_general_interestbooks_general_interest
8764.136363636363643.51computers_accessoriescomputers_accessories
8832.752.01telephonytelephony
89242.751.428571428571431office_furnitureoffice_furniture
9035.05.01furniture_decorfurniture_decor
9123.04.01construction_tools_constructionconstruction_tools_construction
9223.04.02construction_tools_constructionconstruction_tools_construction
9323.03.666666666666673construction_tools_constructionconstruction_tools_construction
9423.03.666666666666674construction_tools_constructionconstruction_tools_construction
9523.03.05construction_tools_constructionconstruction_tools_construction
9643.02.666666666666676construction_tools_constructionconstruction_tools_construction
9723.01.666666666666677construction_tools_constructionconstruction_tools_construction
9893.43.666666666666671housewareshousewares
9943.43.02housewaresbed_bath_table
10023.785714285714292.51furniture_decorconstruction_tools_lights
Rows: 1-100 | Columns: 10