Skip to content

Commit 41c2e56

Browse files
authored
Create acquisition threshold
1 parent c5c67cb commit 41c2e56

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

interview_query/acquisition threshold

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
A bank has two levels of customer acquisition strategies for customers opening new credit cards. Customers are classified into two categories: high spenders and regular spenders, based on their spending habits.
2+
3+
High spenders receive a one-time bonus of $800.
4+
Regular spenders receive a one-time bonus of $100.
5+
Suppose that the bank makes a return based on a percentage of each customer’s spending. The bank wants to attract as many customers as possible while not losing money on this customer acquisition campaign.
6+
7+
Write a Python function that takes in a list of client spending and a return rate to determine the minimum client spending threshold to award the high spender bonus, while having the return on investment be at least as high as the total bonus spend. Make sure to filter out extreme values in the data and return 0 if the return on investment is never as high as the total bonus spent.
8+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9+
10+
We value customers with high spending because we get more from commissions or interest. Therefore, it is important for us to attract and retain such customers. However, it is also important to keep in mind that we should receive at least as much as we spent on the bonuses.
11+
12+
When calculating the threshold to give out bonuses, it is necessary to take into account outliers in the data: some customers may spend significantly more or less than the typical customer, but these cases are usually an exception.
13+
14+
To resolve the issue of outliers, they either need to be eliminated or we can use methods that will not suffer from them. For example, one common method to eliminate outliers is detecting if they are more than 2 standard deviations from the mean spending:
15+
16+
import numpy as np
17+
18+
def get_threshold(spends, return_rate):
19+
high_spender_bonus = 800
20+
regular_spender_bonus = 100
21+
22+
# remove outliers by detecting whether each value is more than 2 standard deviations from the mean
23+
mean = np.mean(spends)
24+
stdev = np.std(spends)
25+
filtered_spends = []
26+
for value in spends:
27+
z_score = (value - mean) / stdev
28+
if abs(z_score) < 2:
29+
filtered_spends.append(value)
30+
31+
total_roi = (sum(filtered_spends) * return_rate)
32+
33+
for threshold in filtered_spends:
34+
high_spenders = [spend for spend in spends if spend >= threshold]
35+
regular_spenders = [spend for spend in spends if spend < threshold]
36+
spend_bonus = (len(high_spenders) * high_spender_bonus + len(regular_spenders) * regular_spender_bonus)
37+
38+
if total_roi > spend_bonus:
39+
return threshold
40+
return 0
41+
Once we have a filtered dataset without the outliers, we can check each spending value to determine if the return on investment is least as great as the spending on the bonuses. If we have iterated through every value without meeting this requirement, the function returns 0 indicating that no spending threshold will break even with the customer acquisition strategy.
42+
43+
Languages
44+
Python 3.10.4
45+
46+
Template
47+
def get_threshold(spends, return_rate):
48+
high_spender_bonus = 800
49+
regular_spender_bonus = 100
50+
pass

0 commit comments

Comments
 (0)