VladGeekPro Copilot commited on
Commit
719b265
·
1 Parent(s): 4b75cf2

PredictSupplierSumTop10

Browse files

Co-authored-by: Copilot <copilot@github.com>

Files changed (1) hide show
  1. expense_predictor.py +4 -15
expense_predictor.py CHANGED
@@ -189,26 +189,15 @@ def predict_expenses(expenses: list[dict], target_user_id, debug: bool = False)
189
  pct = count / total_records * 100
190
  print(f"[PREDICT] supplier_id={supplier_id} -> {count} records ({pct:.1f}%)")
191
 
192
- # Select suppliers whose frequency is strictly greater than 50% of the top supplier frequency
193
- max_freq = max(supplier_freq.values()) if supplier_freq else 0
194
- freq_threshold = 0.5 * max_freq
195
- candidate_items = [
196
- item for item in supplier_history.items()
197
- if supplier_freq[item[0]] > freq_threshold
198
- ]
199
-
200
- # Keep candidates sorted by supplier usage frequency (desc).
201
  candidate_items = sorted(
202
- candidate_items,
203
  key=lambda item: supplier_freq[item[0]],
204
  reverse=True,
205
- )
206
 
207
  if debug:
208
- print(
209
- f"[PREDICT] Processing {len(candidate_items)} suppliers "
210
- f"with freq > 50% of max ({freq_threshold:.2f})"
211
- )
212
 
213
  if not candidate_items:
214
  if debug:
 
189
  pct = count / total_records * 100
190
  print(f"[PREDICT] supplier_id={supplier_id} -> {count} records ({pct:.1f}%)")
191
 
192
+ # Select top 10 most popular suppliers by frequency
 
 
 
 
 
 
 
 
193
  candidate_items = sorted(
194
+ supplier_history.items(),
195
  key=lambda item: supplier_freq[item[0]],
196
  reverse=True,
197
+ )[:10]
198
 
199
  if debug:
200
+ print(f"[PREDICT] Processing top {len(candidate_items)} suppliers")
 
 
 
201
 
202
  if not candidate_items:
203
  if debug: