Pushpak21 commited on
Commit
12c6ea1
·
verified ·
1 Parent(s): 740ad3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import joblib
3
  import pandas as pd
4
  import numpy as np
@@ -42,19 +41,19 @@ def predict():
42
  # Predict probabilities
43
  proba = pipeline.predict_proba(sample_df)[0]
44
 
45
- # Get top-20 indices
46
  top_20_idx = np.argsort(proba)[::-1][:20]
47
 
48
  results = []
49
  for idx in top_20_idx:
50
  choice_code = target_encoder.inverse_transform([idx])[0]
51
- prob = proba[idx]
52
  row = choice_code_map.loc[int(choice_code)]
53
  college_name = row['College Name']
54
  results.append({
55
  "choice_code": choice_code,
56
- "college_name": college_name,
57
- "probability": round(float(prob), 4)
58
  })
59
 
60
  return jsonify({"top_20_predictions": results})
 
 
1
  import joblib
2
  import pandas as pd
3
  import numpy as np
 
41
  # Predict probabilities
42
  proba = pipeline.predict_proba(sample_df)[0]
43
 
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})