Views
No views yet
Low, Medium, or High — from eight numeric features that capture financial, psychological, and behavioral factors.risk_tolerance (categorical):
Low → 0Medium → 1High → 2| Pred High | Pred Low | Pred Medium | |
|---|---|---|---|
| True High | 123 | 0 | 7 |
| True Low | 0 | 135 | 5 |
| True Medium | 10 | 9 | 111 |
xgb_model_Risk_Tolerance_v3.json → trained modelfeature_order_Risk_Tolerance_v3.json → feature order (list of 8 features)label_map_Risk_Tolerance_v3.json → mapping ({"High":0,"Low":1,"Medium":2})1import json, pandas as pd, numpy as np
2from xgboost import XGBClassifier
3from huggingface_hub import hf_hub_download
4
5REPO_ID = "mjpsm/Risk-Tolerance-XGB"
6
7# --- Download artifacts from Hugging Face Hub ---
8model_file = hf_hub_download(REPO_ID, "xgb_model_Risk_Tolerance_v3.json")
9feat_file = hf_hub_download(REPO_ID, "feature_order_Risk_Tolerance_v3.json")
10map_file = hf_hub_download(REPO_ID, "label_map_Risk_Tolerance_v3.json")
11
12# --- Load model + metadata ---
13clf = XGBClassifier()
14clf.load_model(model_file)
15features = json.load(open(feat_file))
16label_map = json.load(open(map_file))
17inv_map = {v:k for k,v in label_map.items()}
18
19# --- Example row ---
20row = {
21 "comfort_with_uncertainty": 8,
22 "savings_to_expense_ratio": 3.2,
23 "runway_months": 14,
24 "debt_to_income_ratio": 0.35,
25 "comfort_with_failure": 7,
26 "entrepreneurial_experience_level": 6,
27 "investment_risk_history": 7,
28 "short_term_vs_long_term_preference": 8,
29}
30
31# --- Predict ---
32X = pd.DataFrame([row])[features].astype("float32").values
33proba = clf.predict_proba(X)[0]
34pred_idx = int(np.argmax(proba))
35print("Prediction:", inv_map[pred_idx], proba)
36