Pushpak21 commited on
Commit
736ea36
·
verified ·
1 Parent(s): 12c6ea1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -44,16 +44,20 @@ def predict():
44
  # Get top-20 indices (highest probabilities)
45
  top_20_idx = np.argsort(proba)[::-1][:20]
46
 
 
 
 
 
47
  results = []
48
- for idx in top_20_idx:
49
  choice_code = target_encoder.inverse_transform([idx])[0]
50
- prob = proba[idx] * 100 # convert to %
51
  row = choice_code_map.loc[int(choice_code)]
52
  college_name = row['College Name']
53
  results.append({
 
54
  "choice_code": choice_code,
55
  "college_name": college_name,
56
- "probability_percent": round(float(prob), 2) # show as %
57
  })
58
 
59
  return jsonify({"top_20_predictions": results})
 
44
  # Get top-20 indices (highest probabilities)
45
  top_20_idx = np.argsort(proba)[::-1][:20]
46
 
47
+ # Normalize top-20 probs to sum to 100
48
+ top_20_probs = proba[top_20_idx]
49
+ top_20_probs_normalized = top_20_probs / top_20_probs.sum() * 100
50
+
51
  results = []
52
+ for rank, (idx, prob) in enumerate(zip(top_20_idx, top_20_probs_normalized), start=1):
53
  choice_code = target_encoder.inverse_transform([idx])[0]
 
54
  row = choice_code_map.loc[int(choice_code)]
55
  college_name = row['College Name']
56
  results.append({
57
+ "rank": rank,
58
  "choice_code": choice_code,
59
  "college_name": college_name,
60
+ "probability_percent": round(float(prob), 2)
61
  })
62
 
63
  return jsonify({"top_20_predictions": results})