Skip to content

Instantly share code, notes, and snippets.

@daydreamersjp
Created May 19, 2022 04:47
Show Gist options
  • Select an option

  • Save daydreamersjp/2f4230d8303f10802bf4a73eb563af17 to your computer and use it in GitHub Desktop.

Select an option

Save daydreamersjp/2f4230d8303f10802bf4a73eb563af17 to your computer and use it in GitHub Desktop.
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from src.models.coupon_distribution import *
# Initialize CouponDistribution object and load data
coupon_dist = CouponDistribution()
coupon_dist.load_data(
customer_data_path="./data/external/customers.csv",
segment_prob_data_path="./data/external/visit_probability.csv")
dict_dm_cost = {"dm1": 0.0, "dm2": 10.0, "dm3": 20.0}
min_dist_ratio = 0.1
unit_sales = 30.0
# Run optimization
coupon_dist.run_optimizer(
dict_dm_cost=dict_dm_cost, min_dist_ratio=min_dist_ratio,
unit_sales=unit_sales, max_budget="optimize")
# Print result KPIs
print(f"Budget: {coupon_dist.max_budget:.2f} USD")
print(f"Profit Increase: {coupon_dist.inc_profit:.2f} USD")
print(f"ROI: {coupon_dist.inc_profit/coupon_dist.max_budget:.2%}")
# Budget: 18895.50 USD
# Profit Increase: 406.50 USD
# ROI: 2.15%
# Print result KPIs if unit_sales = 40
coupon_dist.run_optimizer(
dict_dm_cost=dict_dm_cost, min_dist_ratio=min_dist_ratio,
unit_sales=40, max_budget="optimize")
print(f"Budget: {coupon_dist.max_budget:.2f} USD")
print(f"Profit Increase: {coupon_dist.inc_profit:.2f} USD")
print(f"ROI: {coupon_dist.inc_profit/coupon_dist.max_budget:.2%}")
# Budget: 45719.50 USD
# Profit Increase: 11460.50 USD
# ROI: 25.07%
# Show result dataframe
coupon_dist.df_seg_send_prob
# Visualize result
coupon_dist.visualize_optimized_results()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment