Skip to content

Instantly share code, notes, and snippets.

@meraldo-aliz
Created March 2, 2022 04:52
Show Gist options
  • Save meraldo-aliz/47f54a426b4ba4e52966138fa29568dc to your computer and use it in GitHub Desktop.
Save meraldo-aliz/47f54a426b4ba4e52966138fa29568dc to your computer and use it in GitHub Desktop.
lifetimes
# the predicted number of transactions in the next 10 weeks
rfm_cal_holdout["n_transactions_10_pred"] = bgf.predict(t=10,
frequency=rfm_cal_holdout['frequency_cal'],
recency=rfm_cal_holdout['recency_cal'],
T=rfm_cal_holdout['T_cal'])
# the probability of being alive
rfm_cal_holdout["alive_prob"] = bgf.conditional_probability_alive(frequency=rfm_cal_holdout['frequency_cal'],
recency=rfm_cal_holdout['recency_cal'],
T=rfm_cal_holdout['T_cal'])
# multiplication of alive probability x number of purchases x average past purchase
rfm_cal_holdout["value_10_pred"] = rfm_cal_holdout["alive_prob"]* \
rfm_cal_holdout["n_transactions_10_pred"]*\
rfm_cal_holdout["monetary_value_cal"]
rfm_cal_holdout[["value_10_pred", "alive_prob", "n_transactions_10_pred", "monetary_value_cal"]].head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment