Skip to content

Instantly share code, notes, and snippets.

@h-okay
Last active January 5, 2022 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-okay/57d6d9094510e4d78007bddffccc6ceb to your computer and use it in GitHub Desktop.
Save h-okay/57d6d9094510e4d78007bddffccc6ceb to your computer and use it in GitHub Desktop.
modelling
# Models
bgf = BetaGeoFitter(penalizer_coef=0.001)
bgf.fit(cltv_df['frequency'],
cltv_df['recency'],
cltv_df['T'])
ggf = GammaGammaFitter(penalizer_coef=0.01)
ggf.fit(cltv_df['frequency'], cltv_df['monetary'])
cltv = ggf.customer_lifetime_value(bgf,
cltv_df['frequency'],
cltv_df['recency'],
cltv_df['T'],
cltv_df['monetary'],
time=6,
freq="W",
discount_rate=0.01)
cltv = cltv.reset_index()
cltv_final = cltv_df.merge(cltv, on="Customer ID", how="left")
scaler = MinMaxScaler(feature_range=(0, 1))
scaler.fit(cltv_final[["clv"]])
cltv_final["scaled_clv"] = scaler.transform(cltv_final[["clv"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment