forked from tejones/retailstoreofthefuture
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Training on artificial dataset. (#20)
* Jupyter Notebooks with data prep and training on the artificially-generated dataset. * Adjustment of prediction-service to new parameters.
- Loading branch information
Showing
15 changed files
with
8,063 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
import pandas | ||
|
||
# from .model import PredictionInput | ||
from app.model import PredictionInput | ||
|
||
|
||
class DataEncoder: | ||
_age_range = {'18-25': 0, '26-35': 1, '36-45': 2, '46-55': 3, '56-70': 4, '70+': 5} | ||
_marital_status = {'Married': 0, 'Single': 1} | ||
_gender = {'F': 0, 'M': 1} | ||
_gender = ['F', 'M'] | ||
_age = ['young', 'mid', 'old'] | ||
_categories = ['Boys', 'Girls', 'Men', 'Sports', 'Women'] | ||
_coupon_types = ['biy_all', 'boy_more', 'department', 'just_discount'] | ||
|
||
@classmethod | ||
def encode(cls, input: PredictionInput) -> pandas.DataFrame: | ||
rows = [] | ||
for coupon in input.coupons: | ||
row = { | ||
'customer_id': input.customer.customer_id, | ||
'age_range': cls._age_range[input.customer.age_range], | ||
'marital_status': cls._marital_status[input.customer.marital_status], | ||
'family_size': input.customer.family_size, | ||
'no_of_children': input.customer.no_of_children, | ||
'income_bracket': input.customer.income_bracket, | ||
'gender': cls._gender[input.customer.gender], | ||
'mean_discount_per_cust': input.customer.mean_discount_used, | ||
'unique_items_per_cust': input.customer.total_unique_items_bought, | ||
'mean_quantity_per_cust': input.customer.mean_quantity_bought, | ||
'mean_selling_price_per_cust': input.customer.mean_selling_price_paid, | ||
'total_discount_per_cust': input.customer.total_discount_used, | ||
'total_coupons_used_per_cust': input.customer.total_coupons_redeemed, | ||
'total_quantity_per_cust': input.customer.total_quantity_bought, | ||
'total_selling_price_per_cust': input.customer.total_price_paid, | ||
'cust_credit': input.customer.credit, | ||
'cust_mean_product_price': input.customer.mean_product_price, | ||
'cust_unique_coupons_used': input.customer.unique_coupons_used, | ||
'cust_mean_discount': input.customer.mean_discount_used, | ||
'cust_unique_products_bought': input.customer.unique_items_bought, | ||
'cust_total_products_bougth': input.customer.total_items_bought, | ||
'coupon_id': coupon.coupon_id, | ||
'coupon_discount': coupon.coupon_discount, | ||
'item_selling_price': coupon.item_selling_price | ||
'coupon_how_many': coupon.how_many_products, | ||
'coupon_days_valid': coupon.days_valid, | ||
'coupon_mean_prod_price': coupon.mean_item_selling_price | ||
} | ||
row.update(cls._encode_category(coupon.item_category)) | ||
# row.update(cls._encode_category(coupon.item_category)) | ||
row.update(cls._encode_age(input.customer.age)) | ||
row.update(cls._encode_gender(input.customer.gender)) | ||
row.update(cls._encode_coupon_type(coupon.coupon_type)) | ||
rows.append(row) | ||
|
||
return pandas.DataFrame(rows) | ||
|
||
@classmethod | ||
def _encode_category(cls, category): | ||
return {f'category_{c}': 1 if category == c else 0 for c in cls._categories} | ||
|
||
@classmethod | ||
def _encode_age(cls, age): | ||
return {f'cust_age_{a}': 1 if age == a else 0 for a in cls._age} | ||
|
||
@classmethod | ||
def _encode_gender(cls, gender): | ||
return {f'cust_gender_{g}': 1 if gender == g else 0 for g in cls._gender} | ||
|
||
@classmethod | ||
def _encode_coupon_type(cls, coupon_type): | ||
return {f'coupon_type_{t}': 1 if coupon_type == t else 0 for t in cls._coupon_types} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,523 changes: 3,523 additions & 0 deletions
3,523
training-with-artificial-data/01_data_prep_v1.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.