Ecommerce Purchase Predictor
The eCommerce Purchase Predictor is a smart tool designed to anticipate whether a user is likely to make a purchase or not. By analyzing essential metrics and patterns, this predictor employs machine learning to forecast user behavior accurately. It takes into account factors such as time spent on the website, and user activity. This user-friendly solution aims to empower businesses by providing insights into customer decisions, enabling them to tailor their strategies and enhance the shopping experience. We are working on improving the accuracy of the model.
Running the udf using sample data
We encode the values such as brand, category level1 and category level2 (details below) before calling the udf. The udf returns the prediction whether the user will make a purchase or not.
SELECT
user_session,
code_schema.predict_purchase(
brand_enc.index, // BRAND_OE
category_lvl1_enc.index, //CATEGORY_CODE_LEVEL1_OE,
category_lvl2_enc.index, // CATEGORY_CODE_LEVEL2_OE,
EVENT_WEEKDAY,
activity_count,
price
) as will_purchase
FROM
code_schema.sample_data_view as main
LEFT JOIN
code_schema.brand_encoding_view AS brand_enc
ON main.brand = brand_enc.value
LEFT JOIN
code_schema.category_lvl1_encoding_view AS category_lvl1_enc
ON main.CATEGORY_CODE_LEVEL1 = category_lvl1_enc.value
LEFT JOIN
code_schema.category_lvl2_encoding_view AS category_lvl2_enc
ON main.CATEGORY_CODE_LEVEL2 = category_lvl2_enc.value
Sample Output
We get the response as a column will_purchase that denotes the prediction of whether the user will make a purchase
About the UDF
predict_purchase()
It takes the following data in the specified order
Parameter | Data Type | Description |
---|---|---|
BRAND_ENC | NUMBER | Ordinal Encoded value for brand |
CATEGORY_CODE_LEVEL1_ENC | NUMBER | Ordinal Encoded value for representing top-level category of the product eg: ('elecronics') |
CATEGORY_CODE_LEVEL2_ENC | NUMBER | Ordinal Encoded value for representing sub-level category of the product eg: ('mobile') |
EVENT_WEEKDAY | NUMBER | Numerical representation of event's weekday |
ACTIVITY_COUNT | NUMBER | Count of activities associated with a user event in a session eg: ('view', 'add to cart') |
PRICE | NUMBER | Price of the product |
Using your own data
1. Prepare data in the following structure
Column Name | Data Type | Description |
---|---|---|
USER_SESSION | VARCHAR | Unique identifier for user sessions |
BRAND | VARCHAR | Brand name associated with the product |
PRICE | NUMBER | Price of the product |
EVENT_WEEKDAY | NUMBER | Numerical representation of event's weekday |
CATEGORY_CODE_LEVEL1 | VARCHAR | Code representing top-level category of the product eg: ('elecronics') |
CATEGORY_CODE_LEVEL2 | VARCHAR | Code representing sub-category of the product eg: ('mobile') |
ACTIVITY_COUNT | NUMBER | Count of activities associated with a user event in a session eg: ('view', 'add to cart') |
2. Encode the required columns using mapping views
Encode columns BRAND, CATEGORY_CODE_LEVEL1 & CATEGORY_CODE_LEVEL2 using the column mapping view available on brand_encoding_view, category_lvl1_encoding_view, category_lvl2_encoding_view
Mapping column looks like
Column Name | Data Type | Description |
---|---|---|
VALUE | VARCHAR | Value to be mapped eg: ('samsung') |
INDEX | NUMBER | Ordinal Encoded value |
3. Call the predictor udf with the data
We encode the columns brand, category_code_level1 & category_code_level2 using the encoding views and pass the required data to the udf for getting our prediction
SELECT
user_session,
code_schema.predict_purchase(
brand_enc.index, // BRAND_OE
category_lvl1_enc.index, //CATEGORY_CODE_LEVEL1_OE,
category_lvl2_enc.index, // CATEGORY_CODE_LEVEL2_OE,
EVENT_WEEKDAY,
activity_count,
price
) as will_purchase
FROM
code_schema.sample_data_view as main
LEFT JOIN
code_schema.brand_encoding_view AS brand_enc
ON main.brand = brand_enc.value
LEFT JOIN
code_schema.category_lvl1_encoding_view AS category_lvl1_enc
ON main.CATEGORY_CODE_LEVEL1 = category_lvl1_enc.value
LEFT JOIN
code_schema.category_lvl2_encoding_view AS category_lvl2_enc
ON main.CATEGORY_CODE_LEVEL2 = category_lvl2_enc.value