Spaces:
Runtime error
Runtime error
Download explainer.py from PhunvVi/Credit-risk-predictor: direct link, hf CLI and curl.
- Browser
- Download file 520 Bytes
-
https://huggingface.co/spaces/PhunvVi/Credit-risk-predictor/resolve/main/explainer.py
- Command line
-
hf download hf://spaces/PhunvVi/Credit-risk-predictor/explainer.py
-
curl -L -o explainer.py https://huggingface.co/spaces/PhunvVi/Credit-risk-predictor/resolve/main/explainer.py
520 Bytes
| import shap | |
| import pickle | |
| import pandas as pd | |
| # Load the trained model | |
| with open('model.pkl', 'rb') as f: | |
| model = pickle.load(f) | |
| def get_shap_values(model, input_data): | |
| """ | |
| Returns SHAP values for the given input DataFrame using the trained model. | |
| input_df: pandas DataFrame, preprocessed and matching model input columns | |
| Returns: shap_values, explainer | |
| """ | |
| explainer = shap.TreeExplainer(model) | |
| shap_values = explainer.shap_values(input_data) | |
| return shap_values, explainer | |