Spaces:
Running
Running
| import pandas as pd | |
| import xgboost as xgb | |
| import numpy as np | |
| # Load data and model | |
| df = pd.read_csv("data/processed/app_features.csv") | |
| mv_rename_map = {col: 'market_value_in_eur' for col in df.columns if 'market' in col.lower() and 'value' in col.lower()} | |
| if mv_rename_map: | |
| df.rename(columns=mv_rename_map, inplace=True) | |
| df = df.loc[:, ~df.columns.duplicated()].copy() | |
| model = xgb.XGBRegressor() | |
| model.load_model("fairvalue_xgboost.json") | |
| expected_cols = model.feature_names_in_ | |
| player_data = df.median(numeric_only=True).to_frame().T | |
| # Simulate what api/main.py does | |
| player_data['Contract_Years_Left'] = 2.5 | |
| player_data['Age'] = 28 | |
| player_data['market_value_in_eur'] = (120 * 1_000_000) / 0.85 | |
| X_infer = player_data.reindex(columns=expected_cols, fill_value=0) | |
| preds = model.predict(X_infer) | |
| log_pv = preds[0] | |
| baseline_pv = np.expm1(log_pv) | |
| print(f"Log PV: {log_pv}") | |
| print(f"Baseline PV (Euros): {baseline_pv}") | |
| print(f"Baseline PV_m (Millions): {baseline_pv / 1_000_000}") | |