Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
1 0 0 224
2 6 142 292
3 0 0 147
4 2 9 183
>>> print fitted_bg.predict(30, t['frequency'], t['recency'], t['T'])
0 0.016053
1 0.021171
2 0.030461
3 0.031686
4 0.001607
dtype: float64
"""
t = fitted_bg.data.head()
expected = np.array([0.016053, 0.021171, 0.030461, 0.031686, 0.001607])
# discount_rate=0 means the clv will be the same as the predicted
clv_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=0.)
assert_almost_equal(clv_d0.values, expected, decimal=5)
# discount_rate=1 means the clv will halve over a period
clv_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=1.)
assert_almost_equal(clv_d1.values, expected / 2., decimal=5)
# time=2, discount_rate=0 means the clv will be twice the initial
clv_t2_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=0)
assert_allclose(clv_t2_d0.values, expected * 2., rtol=0.1)
# time=2, discount_rate=1 means the clv will be twice the initial
clv_t2_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=1.)
assert_allclose(clv_t2_d1.values, expected / 2. + expected / 4., rtol=0.1)
1 0.021171
2 0.030461
3 0.031686
4 0.001607
dtype: float64
"""
t = fitted_bg.data.head()
expected = np.array([0.016053, 0.021171, 0.030461, 0.031686, 0.001607])
# discount_rate=0 means the clv will be the same as the predicted
clv_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=0.)
assert_almost_equal(clv_d0.values, expected, decimal=5)
# discount_rate=1 means the clv will halve over a period
clv_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=1.)
assert_almost_equal(clv_d1.values, expected / 2., decimal=5)
# time=2, discount_rate=0 means the clv will be twice the initial
clv_t2_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=0)
assert_allclose(clv_t2_d0.values, expected * 2., rtol=0.1)
# time=2, discount_rate=1 means the clv will be twice the initial
clv_t2_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=1.)
assert_allclose(clv_t2_d1.values, expected / 2. + expected / 4., rtol=0.1)
4 0.001607
dtype: float64
"""
t = fitted_bg.data.head()
expected = np.array([0.016053, 0.021171, 0.030461, 0.031686, 0.001607])
# discount_rate=0 means the clv will be the same as the predicted
clv_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=0.)
assert_almost_equal(clv_d0.values, expected, decimal=5)
# discount_rate=1 means the clv will halve over a period
clv_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=1.)
assert_almost_equal(clv_d1.values, expected / 2., decimal=5)
# time=2, discount_rate=0 means the clv will be twice the initial
clv_t2_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=0)
assert_allclose(clv_t2_d0.values, expected * 2., rtol=0.1)
# time=2, discount_rate=1 means the clv will be twice the initial
clv_t2_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=1.)
assert_allclose(clv_t2_d1.values, expected / 2. + expected / 4., rtol=0.1)
4 2 9 183
>>> print fitted_bg.predict(30, t['frequency'], t['recency'], t['T'])
0 0.016053
1 0.021171
2 0.030461
3 0.031686
4 0.001607
dtype: float64
"""
t = fitted_bg.data.head()
expected = np.array([0.016053, 0.021171, 0.030461, 0.031686, 0.001607])
# discount_rate=0 means the clv will be the same as the predicted
clv_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=0.)
assert_almost_equal(clv_d0.values, expected, decimal=5)
# discount_rate=1 means the clv will halve over a period
clv_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=1, discount_rate=1.)
assert_almost_equal(clv_d1.values, expected / 2., decimal=5)
# time=2, discount_rate=0 means the clv will be twice the initial
clv_t2_d0 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=0)
assert_allclose(clv_t2_d0.values, expected * 2., rtol=0.1)
# time=2, discount_rate=1 means the clv will be twice the initial
clv_t2_d1 = utils._customer_lifetime_value(fitted_bg, t['frequency'], t['recency'], t['T'], monetary_value=pd.Series([1, 1, 1, 1, 1]), time=2, discount_rate=1.)
assert_allclose(clv_t2_d1.values, expected / 2. + expected / 4., rtol=0.1)
discount_rate: float, optional
the monthly adjusted discount rate. Default: 0.01
freq: string, optional
{"D", "H", "M", "W"} for day, hour, month, week. This represents what unit of time your T is measure in.
Returns
-------
Series:
Series object with customer ids as index and the estimated customer
lifetime values as values
"""
# use the Gamma-Gamma estimates for the monetary_values
adjusted_monetary_value = self.conditional_expected_average_profit(frequency, monetary_value)
return _customer_lifetime_value(
transaction_prediction_model, frequency, recency, T, adjusted_monetary_value, time, discount_rate, freq=freq
)