Spaces:
Sleeping
Sleeping
GMARTINEZMILLA
commited on
Commit
•
ef1d523
1
Parent(s):
57b289e
feat: updated app.py
Browse files
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
|
278 |
-
|
279 |
|
280 |
# Convert cliente_id to string
|
281 |
-
|
282 |
|
283 |
-
st.write("###
|
284 |
-
st.write(
|
285 |
-
st.write(f"Shape: {
|
286 |
|
287 |
# Filter for the specific customer
|
288 |
customer_code_str = str(customer_code)
|
289 |
-
|
290 |
|
291 |
# Add debug statements
|
292 |
-
st.write(f"Unique customer IDs in
|
293 |
st.write(f"Customer code we're looking for: {customer_code_str}")
|
294 |
|
295 |
-
st.write("###
|
296 |
-
st.write(
|
297 |
-
st.write(f"Shape: {
|
298 |
|
299 |
-
if not
|
|
|
|
|
|
|
|
|
300 |
# Prepare data for prediction
|
301 |
-
|
302 |
st.write("### Features for Prediction:")
|
303 |
-
st.write(
|
304 |
-
st.write(f"Shape: {
|
305 |
|
306 |
# Make Prediction for the selected customer
|
307 |
-
y_pred = gbm.predict(
|
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 =
|
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())
|