Views
No views yet
1import torch
2import joblib
3from huggingface_hub import hf_hub_download
4
5# Download files
6model_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="best_mlp_model.pth")
7architecture_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="model_architecture.py")
8scaler_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="scaler.pkl")
9config_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="config.json")
10
11# Load architecture
12import importlib.util
13spec = importlib.util.spec_from_file_location("model_architecture", architecture_path)
14model_module = importlib.util.module_from_spec(spec)
15spec.loader.exec_module(model_module)
16
17# Load model
18model = model_module.MLP(input_dim=22, hidden_dims=[128, 64, 32], dropout_rate=0.3)
19model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
20model.eval()
21
22# Load scaler
23scaler = joblib.load(scaler_path)
24
25# Make prediction
26# X_new should be a pandas DataFrame or numpy array with the correct features
27X_scaled = scaler.transform(X_new)
28X_tensor = torch.FloatTensor(X_scaled)
29with torch.no_grad():
30 xg_prediction = model(X_tensor).numpy()