Instructions to Run Nursery XAI
Assignment Code
1. Environment Setup
Before running the code, ensure you have Python 3.8 or later installed. It is recommended
to use a virtual environment.
2. Required Libraries
Install the following Python libraries using pip:
pip install pandas numpy scikit-learn xgboost matplotlib seaborn
shap lime ucimlrepo
Note: If you encounter an error with SHAP installation, install the required C++ build tools
from:
https://visualstudio.microsoft.com/visual-cpp-build-tools/
3. Running the Script
1. Save the assignment code in a Python file, e.g., Nursery_XAI_Assignment.py.
2. Open VS Code or any code editor of your choice.
3. Navigate to the folder containing the script.
4. Run the script using the command:
python Nursery_XAI_Assignment.py
This will:
- Download and process the Nursery dataset.
- Train Decision Tree, Random Forest, and XGBoost models.
- Evaluate model performance.
- Generate SHAP and LIME explainability plots.
- Save the outputs (plots and explanations) in the working directory.
4. Output Files
The following files will be generated:
- shap_summary_<class>.png — SHAP plots for each class.
- lime_explanation.html — LIME explanation for one prediction.
- rf_feature_importance.png — Random Forest feature importance plot.
- feature_importance_decision_tree.png — Decision Tree feature importance plot.
5. Troubleshooting
- If SHAP fails to install, ensure you have Microsoft C++ Build Tools installed.
- If 'pip' is not recognized, make sure Python and pip are added to your system PATH.
- Use 'python -m pip install <package>' if pip alone doesn't work.