niladridutta commited on
Commit
fb52313
1 Parent(s): 6e16db1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -50,14 +50,14 @@ if uploaded_file is not None:
50
  summary['probability_alive'] = bgf.conditional_probability_alive(summary['frequency'], summary['recency'], summary['T'])
51
  #Predict future transaction for the next 300 days based on historical dataa
52
  t = 300
53
- summary['pred_num_txn'] = round(bgf.conditional_expected_number_of_purchases_up_to_time(t, summary['frequency'], summary['recency'], summary['T']),2)
54
- summary.sort_values(by='pred_num_txn', ascending=False).head(10).reset_index()
55
  #Hidden trends
56
- ax = sns.countplot(x="pred_num_txn",data=summary)
57
- plt.scatter(summary['probability_alive'],summary['pred_num_txn'])
58
  summary_correlation=summary.corr()
59
  summary1=summary
60
- summary1['Active/Inactive']=summary1['pred_num_txn'].apply(lambda x:"ACTIVE" if x>=1 else "INACTIVE")
61
  selector=st.selectbox('Select User ID',summary1['CustomerID'],index=None,placeholder='Select Customer ID')
62
  summary2=summary1[['CustomerID','Active/Inactive']]
63
  if selector is not None:
@@ -65,9 +65,9 @@ if uploaded_file is not None:
65
  st.write('STATUS:',selected)
66
  trends= data_clv.groupby('CustomerID')['Quantity'].mean().reset_index()
67
  trends1= data_clv.groupby('CustomerID')['TotalSales'].mean().reset_index()
68
- trends.at[0,'Quantity']=7.42
69
- trends1.at[0,'TotalSales']=77.183
70
  summary1=summary1.merge(trends, how='left',on='CustomerID')
71
  summary1=summary1.merge(trends1, how='left',on='CustomerID')
 
 
72
  out=summary1.to_csv().encode('utf-8')
73
  st.download_button(label='DOWNLOAD RESULT',data=out, file_name='CLV_OUTPUT.csv',mime='text/csv')
 
50
  summary['probability_alive'] = bgf.conditional_probability_alive(summary['frequency'], summary['recency'], summary['T'])
51
  #Predict future transaction for the next 300 days based on historical dataa
52
  t = 300
53
+ summary['Predicted No. of Transaction'] = round(bgf.conditional_expected_number_of_purchases_up_to_time(t, summary['frequency'], summary['recency'], summary['T']),2)
54
+ summary.sort_values(by='Predicted No. of Transaction', ascending=False).head(10).reset_index()
55
  #Hidden trends
56
+ ax = sns.countplot(x="Predicted No. of Transaction",data=summary)
57
+ plt.scatter(summary['probability_alive'],summary['Predicted No. of Transaction'])
58
  summary_correlation=summary.corr()
59
  summary1=summary
60
+ summary1['Active/Inactive']=summary1['Predicted No. of Transaction'].apply(lambda x:"ACTIVE" if x>=1 else "INACTIVE")
61
  selector=st.selectbox('Select User ID',summary1['CustomerID'],index=None,placeholder='Select Customer ID')
62
  summary2=summary1[['CustomerID','Active/Inactive']]
63
  if selector is not None:
 
65
  st.write('STATUS:',selected)
66
  trends= data_clv.groupby('CustomerID')['Quantity'].mean().reset_index()
67
  trends1= data_clv.groupby('CustomerID')['TotalSales'].mean().reset_index()
 
 
68
  summary1=summary1.merge(trends, how='left',on='CustomerID')
69
  summary1=summary1.merge(trends1, how='left',on='CustomerID')
70
+ summary1.drop('probability_alive',axis=1,inplace=True)
71
+ summary1.rename(columns={'Quantity':'Average Quantity','TotalSales':'Average Sales Value'})
72
  out=summary1.to_csv().encode('utf-8')
73
  st.download_button(label='DOWNLOAD RESULT',data=out, file_name='CLV_OUTPUT.csv',mime='text/csv')