CamDavidsonPilon / lifetimes

Lifetime value in Python
MIT License
1.45k stars 374 forks source link

Issue plotting P_alive #231

Closed alistairallan closed 3 months ago

alistairallan commented 5 years ago

I'm running the following code in a local Jupyter Notebook. https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/CLV_Online_Retail.ipynb I had an issue with Matplotlib after installing Lifetimes and had to reinstall via Conda.

The code all runs as expected, predict works etc and all the plots run correctly except for plot_history_alive which only plots the purchases, but not P_alive.

I get no errors or warnings.

I can run predict on different period lengths for different customers and it runs fine, so might be related to the libraries? I had a quick look at the plot_history_alive function but I couldn't see any reason why it shouldn't work.

I'm using:

matplotlib==2.2.2
pandas==0.23.4
lifetimes==0.9.1.0

Any ideas on where I should look first to debug?

Thanks A

aprotopopov commented 5 years ago

@alistairallan Do you have issues with all datasets or only with yours? Does the plot look correct with CDNOW data?

teresadong commented 5 years ago

I was able to get the CDNOW data to work see: https://colab.research.google.com/drive/1oc8vbnG-kHc_xaSZStNBH3e1R_VFboqb

But I wasn't able to get https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/CLV_Online_Retail.ipynb to work. Please see: https://colab.research.google.com/drive/15Ab4lbeai0TnVcaWOKF2ObpEtQVNnhuQ

image

In the original github, it looked like this:

image

The changes I made to the notebook were as follows: I downgraded scipy from 1.2.0 to 1.1.0 because of: https://github.com/CamDavidsonPilon/lifetimes/issues/274

I commented out from lifetimes.estimation import * because it doesn't seem to exist anymore

Thanks! Teresa

maria-ferreira-olx commented 5 years ago

I have the same issue, were you able to fix it?

ZhengTzer commented 4 years ago

I have the same issue, any solution?

traveler1602 commented 4 years ago

I have the same issue as well.

FakieKickflip commented 3 years ago

My fault was, that I did not check the actual p_alive value in the plot for that specific userID/customerID. It was a path full of 1 and hide on the top in the graph.

I entered a little print statement in the lifetimes.plotting.plot_history_alive to check the values on the path coming back from the function.

    # plot alive_path
    path = calculate_alive_path(model, transactions, datetime_col, t, freq)
    print(path.head())
    path_dates = pd.date_range(start=min(transactions[datetime_col]), periods=len(path), freq=freq)

Et voila, they were just ones. So if you got no p_alive path in your plot, check the actual path values for that line. This could be the issue. :-)

fpannacci commented 2 years ago

I'm having the same issue and following @FakieKickflip I discovered I have all ones. Do you know which can cause this? I have a dataframe in which all customers gets P_alive=1 for long time, I think is not possible...

Schermata 2021-12-23 alle 12 02 13

This is what happens if I set t=10000

FakieKickflip commented 2 years ago

@fpannacci hard to figure out what is going on. In your plot the customer bought last in around 2014, 2015. It can not be right that he is an alive customer in 2021 and beyond.

fpannacci commented 2 years ago

Yes right...the data comes from here [https://www.kaggle.com/apoorvaappz/global-super-store-dataset] and the customer ID I'm looking at is NZ-18565