-
Notifications
You must be signed in to change notification settings - Fork 291
Allow covariates in plot_expected_purchases
#1430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Allow covariates in plot_expected_purchases
#1430
Conversation
…taGeoModel. Add some tests
…thCovariates.test_extract_predictive_covariates
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1430 +/- ##
==========================================
- Coverage 91.59% 91.51% -0.08%
==========================================
Files 60 60
Lines 6782 6802 +20
==========================================
+ Hits 6212 6225 +13
- Misses 570 577 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I'll review this in detail later, but it looks like there may be merge conflicts with #1390 |
@ColtAllen Feel free to have a look at this PR whenever you have some spare time. It is ready for review from my side. |
Is there documentation available for these datasets? I wasn't able to find anything in the R library.
Is it possible to consolidate this into the existing BG/NBD notebook? |
Link to apparelTrans and apparelStaticCov
Do you propose to add this new dataset, or use the synthetic covariates that we are using in the ParetoNBD notebook? |
Nice, so this dataset is simulated, then.
The Pareto/NBD notebook is using real data available here. I think using the same dataset would make for a good comparison in resolving #1496. That said, let's just remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the covariate data already being saved in a fitted model rather than require the user to add this to the transaction data (see my comment for more details). This should cut down on the additional code/testing requirements and also be more efficient.
One of these days I'd like to refactor _expected_cumulative_transactions
to eliminate the FOR loop, but this would require xarray
support in the predictive methods.
if model.purchase_covariate_cols or model.dropout_covariate_cols: | ||
distinct_covariates_cols = list( | ||
set(model.purchase_covariate_cols).intersection( | ||
set(model.dropout_covariate_cols) | ||
) | ||
) | ||
distinct_covariates = transactions[distinct_covariates_cols].drop_duplicates() | ||
else: | ||
distinct_covariates_cols = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a customer_id dimension for the covariates in the fitted model idata
. Rather than requiring covariates be added to be transaction dataframe, we can obtain the covariates from the model directly and merge them with repeated_and_first_transactions
.
@PabloRoque can we bring this one to the finish line? |
Description
Includes covariates when calculation the unconditional frequency expectation. Allows the estimation of future purchases for the "average customer" just after first order for models with covariates.
Additionally:
apparel_trans.csv
and accompanyingapparel_static_cov.csv
. These datasets are extracted from R's CLVTools package.bg_nbd_covariates.ipynb
shows an example of the new functionality using the new dataset.Related Issue
Checklist
pre-commit.ci autofix
to auto-fix.📚 Documentation preview 📚: https://pymc-marketing--1430.org.readthedocs.build/en/1430/