ShadowGard3n commited on
Commit
ed511fd
·
1 Parent(s): 03b8b34

Debugging+++

Browse files
Files changed (1) hide show
  1. services/market_services.py +16 -16
services/market_services.py CHANGED
@@ -73,8 +73,17 @@ def get_market_prediction(model, df_full, commodity, last_known_date):
73
  """
74
  Iteratively predicts the next 180 days.
75
  """
76
- print(f"--- PREDICTION STARTED FOR {commodity} ---") # DEBUG PRINT
77
 
 
 
 
 
 
 
 
 
 
78
  df_commodity = df_full[df_full['commodity'] == commodity]
79
  df_daily = df_commodity.groupby(df_commodity.index).agg({'modal_price': 'mean'})
80
 
@@ -95,29 +104,20 @@ def get_market_prediction(model, df_full, commodity, last_known_date):
95
  if target_row[feature_names].isna().any():
96
  continue
97
 
98
- # --- CRITICAL FIX SECTION ---
99
- # 1. Extract values
100
  input_values = target_row[feature_names].values.reshape(1, -1)
101
 
102
- # 2. Create DataFrame
103
- input_df = pd.DataFrame(input_values, columns=feature_names)
104
-
105
- # 3. DEBUG: Check if we are passing a DataFrame
106
- # If you don't see this print in your terminal, the old code is still running!
107
- if date == future_dates[0]:
108
- print("TYPE CHECK:", type(input_df))
109
- print("COLUMNS CHECK:", input_df.columns.tolist())
110
-
111
- # 4. Predict
112
- prediction = model.predict(input_df)[0]
113
- # -----------------------------
114
 
115
  df_extended.loc[date, 'modal_price'] = prediction
116
 
117
  daily_forecast_df = df_extended.loc[future_dates].copy()
118
  daily_forecast_df.rename(columns={'modal_price': 'forecast'}, inplace=True)
119
 
120
- print("--- PREDICTION SUCCESS ---") # DEBUG PRINT
121
  return daily_forecast_df
122
 
123
 
 
73
  """
74
  Iteratively predicts the next 180 days.
75
  """
76
+ print(f"--- PREDICTION STARTED FOR {commodity} ---")
77
 
78
+ # --- FIX START: DISABLE FEATURE NAME CHECK ---
79
+ # This tells XGBoost: "Don't check column names, just trust the order of numbers I give you"
80
+ try:
81
+ booster = model.get_booster()
82
+ booster.feature_names = None
83
+ except Exception:
84
+ pass # If it fails, we proceed anyway
85
+ # --- FIX END ---
86
+
87
  df_commodity = df_full[df_full['commodity'] == commodity]
88
  df_daily = df_commodity.groupby(df_commodity.index).agg({'modal_price': 'mean'})
89
 
 
104
  if target_row[feature_names].isna().any():
105
  continue
106
 
107
+ # 1. Extract values as a plain Numpy Array
108
+ # Reshape to (1, 11) -> 1 row, 11 features
109
  input_values = target_row[feature_names].values.reshape(1, -1)
110
 
111
+ # 2. Predict using the Numpy Array directly (Faster & Safer now)
112
+ # Since we disabled feature_names check, this will now work.
113
+ prediction = model.predict(input_values)[0]
 
 
 
 
 
 
 
 
 
114
 
115
  df_extended.loc[date, 'modal_price'] = prediction
116
 
117
  daily_forecast_df = df_extended.loc[future_dates].copy()
118
  daily_forecast_df.rename(columns={'modal_price': 'forecast'}, inplace=True)
119
 
120
+ print("--- PREDICTION SUCCESS ---")
121
  return daily_forecast_df
122
 
123