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.
|
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:
|
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)
In [55]:
# Recommendation based on the Frequencies
order_items.recommend("order_id",
"product_id",)
Out[55]:
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]:
