ColtAllen / btyd

Buy Till You Die and Customer Lifetime Value statistical models in Python.
https://btyd.readthedocs.io/
Apache License 2.0
114 stars 9 forks source link

Merge BetaGeo Time-Invariant Covariates model into Main Branch. #13

Closed ColtAllen closed 2 years ago

ColtAllen commented 2 years ago

Merging BetaGeo Time-Invariant Covariates model from feature sub-branch into main master branch:

It is worth noting the PR #11 with the base lifetimes repo is failing tests/test_estimation.py::TestGammaGammaFitter::test_customer_lifetime_value_with_bgf:

def test_customer_lifetime_value_with_bgf(self, cdnow_customers_with_monetary_value):

        ggf = lt.GammaGammaFitter()
        ggf.params_ = pd.Series({"p": 6.25, "q": 3.74, "v": 15.44})

        bgf = lt.BetaGeoFitter()
        bgf.fit(
            cdnow_customers_with_monetary_value["frequency"],
            cdnow_customers_with_monetary_value["recency"],
            cdnow_customers_with_monetary_value["T"],
        )

        ggf_clv = ggf.customer_lifetime_value(
            bgf,
            cdnow_customers_with_monetary_value["frequency"],
            cdnow_customers_with_monetary_value["recency"],
            cdnow_customers_with_monetary_value["T"],
            cdnow_customers_with_monetary_value["monetary_value"],
        )

        utils_clv = utils._customer_lifetime_value(
            bgf,
            cdnow_customers_with_monetary_value["frequency"],
            cdnow_customers_with_monetary_value["recency"],
            cdnow_customers_with_monetary_value["T"],
            ggf.conditional_expected_average_profit(
                cdnow_customers_with_monetary_value["frequency"], cdnow_customers_with_monetary_value["monetary_value"]
            ),
        )
>       npt.assert_equal(ggf_clv.values, utils_clv.values)
E       AssertionError: 
E       Arrays are not equal
E       
E       x and y nan location mismatch:
E        x: array([140.12518 ,  18.948848,  38.232656, ...,  47.335732, 466.544731,
E               47.335732])
E        y: array([       nan, 140.12518 ,  18.948848, ..., 712.964802,  47.335732,
E              466.544731])

tests/test_estimation.py:223: AssertionError

However, this matter is largely inconsequential as both models will be refactored to run on the pymc4 backend and deprecated.