GMARTINEZMILLA commited on
Commit
ef1d523
1 Parent(s): 57b289e

feat: updated app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -274,37 +274,41 @@ elif page == "Customer Analysis":
274
  st.write("Feature names:")
275
  st.write(gbm.feature_name())
276
 
277
- # Load X_predict for that cluster
278
- X_predict_cluster = pd.read_csv(f'predicts/X_predict_cluster_{cluster}.csv')
279
 
280
  # Convert cliente_id to string
281
- X_predict_cluster['cliente_id'] = X_predict_cluster['cliente_id'].astype(str)
282
 
283
- st.write("### X_predict_cluster DataFrame:")
284
- st.write(X_predict_cluster.head())
285
- st.write(f"Shape: {X_predict_cluster.shape}")
286
 
287
  # Filter for the specific customer
288
  customer_code_str = str(customer_code)
289
- X_cliente = X_predict_cluster[X_predict_cluster['cliente_id'] == customer_code_str]
290
 
291
  # Add debug statements
292
- st.write(f"Unique customer IDs in X_predict_cluster: {X_predict_cluster['cliente_id'].unique()}")
293
  st.write(f"Customer code we're looking for: {customer_code_str}")
294
 
295
- st.write("### X_cliente DataFrame:")
296
- st.write(X_cliente.head())
297
- st.write(f"Shape: {X_cliente.shape}")
298
 
299
- if not X_cliente.empty:
 
 
 
 
300
  # Prepare data for prediction
301
- features_for_prediction = X_cliente.drop(columns=['cliente_id', 'fecha_mes'])
302
  st.write("### Features for Prediction:")
303
- st.write(features_for_prediction.head())
304
- st.write(f"Shape: {features_for_prediction.shape}")
305
 
306
  # Make Prediction for the selected customer
307
- y_pred = gbm.predict(features_for_prediction, num_iteration=gbm.best_iteration)
308
  st.write("### Prediction Results:")
309
  st.write(f"Type of y_pred: {type(y_pred)}")
310
  st.write(f"Shape of y_pred: {y_pred.shape}")
@@ -312,7 +316,7 @@ elif page == "Customer Analysis":
312
  st.write(y_pred[:5])
313
 
314
  # Reassemble the results
315
- results = X_cliente[['cliente_id', 'marca_id_encoded', 'fecha_mes']].copy()
316
  results['ventas_predichas'] = y_pred
317
  st.write("### Results DataFrame:")
318
  st.write(results.head())
 
274
  st.write("Feature names:")
275
  st.write(gbm.feature_name())
276
 
277
+ # Load predict data for that cluster
278
+ predict_data = pd.read_csv(f'predicts/predict_cluster_{cluster}.csv')
279
 
280
  # Convert cliente_id to string
281
+ predict_data['cliente_id'] = predict_data['cliente_id'].astype(str)
282
 
283
+ st.write("### Predict Data DataFrame:")
284
+ st.write(predict_data.head())
285
+ st.write(f"Shape: {predict_data.shape}")
286
 
287
  # Filter for the specific customer
288
  customer_code_str = str(customer_code)
289
+ customer_data = predict_data[predict_data['cliente_id'] == customer_code_str]
290
 
291
  # Add debug statements
292
+ st.write(f"Unique customer IDs in predict data: {predict_data['cliente_id'].unique()}")
293
  st.write(f"Customer code we're looking for: {customer_code_str}")
294
 
295
+ st.write("### Customer Data:")
296
+ st.write(customer_data.head())
297
+ st.write(f"Shape: {customer_data.shape}")
298
 
299
+ if not customer_data.empty:
300
+ # Define features consistently with the training process
301
+ lag_features = [f'precio_total_lag_{lag}' for lag in range(1, 25)]
302
+ features = lag_features + ['mes', 'marca_id_encoded', 'año', 'cluster_id']
303
+
304
  # Prepare data for prediction
305
+ X_predict = customer_data[features]
306
  st.write("### Features for Prediction:")
307
+ st.write(X_predict.head())
308
+ st.write(f"Shape: {X_predict.shape}")
309
 
310
  # Make Prediction for the selected customer
311
+ y_pred = gbm.predict(X_predict, num_iteration=gbm.best_iteration)
312
  st.write("### Prediction Results:")
313
  st.write(f"Type of y_pred: {type(y_pred)}")
314
  st.write(f"Shape of y_pred: {y_pred.shape}")
 
316
  st.write(y_pred[:5])
317
 
318
  # Reassemble the results
319
+ results = customer_data[['cliente_id', 'marca_id_encoded', 'fecha_mes']].copy()
320
  results['ventas_predichas'] = y_pred
321
  st.write("### Results DataFrame:")
322
  st.write(results.head())