mednow commited on
Commit
c857a68
·
verified ·
1 Parent(s): 65b3efa

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -28,8 +28,8 @@ if uploaded_file is not None:
28
  # One-hot encode categorical features for the predictive model
29
  data_encoded = pd.get_dummies(data, columns=['Gender', 'Purchase_Category'], drop_first=True)
30
 
31
- # Assuming 'Return' variable can be derived from a condition, like Purchase_Frequency > 1
32
- data_encoded['Return'] = (data['Purchase_Frequency'] > 1).astype(int) # Example condition for return status
33
 
34
  X = data_encoded.drop(columns=['Customer_ID', 'Return']) # Features
35
  y = data_encoded['Return'] # Return as the target variable
@@ -81,6 +81,7 @@ if uploaded_file is not None:
81
  st.write("No associations found for the selected product.")
82
 
83
  elif model_choice == 'Customers Who Will Return':
 
84
  st.header("Customers Predicted to Return")
85
 
86
  # Make predictions for all customers
@@ -92,5 +93,13 @@ if uploaded_file is not None:
92
  # Filter customers who will return
93
  customers_will_return = data[data['Predicted_Return'] == 1]
94
 
 
 
 
 
 
 
 
 
95
  # Display the customers who will return
96
- st.dataframe(customers_will_return[['Customer_ID', 'Age', 'Gender', 'Income', 'Purchase_Frequency']])
 
28
  # One-hot encode categorical features for the predictive model
29
  data_encoded = pd.get_dummies(data, columns=['Gender', 'Purchase_Category'], drop_first=True)
30
 
31
+ # Assuming 'Return' variable can be derived from a condition, like Purchase_Frequency > 2
32
+ data_encoded['Return'] = (data['Purchase_Frequency'] > 2).astype(int) # Example condition for return status
33
 
34
  X = data_encoded.drop(columns=['Customer_ID', 'Return']) # Features
35
  y = data_encoded['Return'] # Return as the target variable
 
81
  st.write("No associations found for the selected product.")
82
 
83
  elif model_choice == 'Customers Who Will Return':
84
+
85
  st.header("Customers Predicted to Return")
86
 
87
  # Make predictions for all customers
 
93
  # Filter customers who will return
94
  customers_will_return = data[data['Predicted_Return'] == 1]
95
 
96
+ # Group by Customer_ID and aggregate other fields (you can customize this as needed)
97
+ customers_will_return = customers_will_return.groupby('Customer_ID').agg({
98
+ 'Age': 'first', # or 'mean', depending on your preference
99
+ 'Gender': 'first',
100
+ 'Income': 'first',
101
+ 'Purchase_Frequency': 'sum' # Aggregate if there are multiple entries
102
+ }).reset_index()
103
+
104
  # Display the customers who will return
105
+ st.dataframe(customers_will_return)