Evaluate feature importance for LightGBM models using various methods.
Project description
lightgbm_feature_importance_evaluator_zhoumath
A Python package for evaluating feature importance in LightGBM models using various methods. This package is tailored for LightGBM users but also supports model-agnostic feature importance evaluation methods, such as permutation and drop-column importance.
Key Features
- LightGBM-Specific Importance Methods:
- Gain-based importance.
- Split-based importance.
- Model-Agnostic Methods:
- Permutation importance.
- Drop-column importance.
- SHAP-Based Interpretability:
- Local and global explanations using SHAP values.
- Cross-Validation Support:
- Robust feature importance evaluation using stratified k-fold cross-validation.
- Feature Filtering:
- Select important features based on a user-defined threshold.
Installation
You can install the package directly from PyPI: pip install lightgbm_feature_importance_evaluator_zhoumath
Usage Here鈥檚 how to use lightgbm_feature_importance_evaluator_zhoumath step by step:
-
Import the Package from lightgbm_feature_importance_evaluator_zhoumath.evaluator import FeatureImportanceEvaluator from lightgbm import LGBMClassifier import pandas as pd
-
Prepare Your Dataset
Sample dataset
data = pd.DataFrame({ "feature1": [1, 2, 3, 4, 5], "feature2": [5, 4, 3, 2, 1], "feature3": [2, 3, 4, 5, 6], "target": [0, 1, 0, 1, 0], "timestamp": ["2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04", "2023-01-05"] })
-
Initialize the Evaluator evaluator = FeatureImportanceEvaluator( data=data, target_column="target", timestamp_column="timestamp", feature_columns=["feature1", "feature2", "feature3"], model=LGBMClassifier(), importance_method="gain", # Choose from 'gain', 'split', 'permutation', 'shap', 'drop_column' )
-
Evaluate Feature Importance importance_df = evaluator.evaluate_importance() print("Feature Importance:") print(importance_df)
-
Filter Features selected_features, sorted_importance = evaluator.get_filtered_features(importance_df) print("Selected Features:") print(selected_features)
Available Importance Methods: gain #Importance based on the gain (performance improvement) when a feature is used for splitting. split #Importance based on the frequency a feature is used for splitting. permutation #Model-agnostic importance based on the drop in performance when a feature is randomly shuffled. shap #Uses SHAP values to explain the contribution of each feature to predictions. drop_column #Measures the change in model performance when a feature is entirely removed from the dataset.
Customization Options Cross-Validation: Adjust the number of splits using n_splits. Repeat cross-validation multiple times using repeats. Importance Threshold: Filter features with importance above a specific threshold using importance_threshold. Date Filtering: Use start_date and end_date to filter data based on a time range.
Dependencies The package requires the following Python libraries: numpy pandas scikit-learn shap lightgbm Install them with: pip install -r requirements.txt
License This project is licensed under the MIT License - see the LICENSE file for details.
Contributing Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.
Acknowledgments This package was developed to streamline the evaluation of feature importance in LightGBM models and simplify workflows for data scientists and machine learning practitioners.
Author Zhoushus Email: zhoushus@foxmail.com GitHub: https://github.com/shanghaizhoushus
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lightgbm_feature_importance_evaluator_zhoumath-0.1.0.tar.gz.
File metadata
- Download URL: lightgbm_feature_importance_evaluator_zhoumath-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71edd6024c1c4ee01cc9c37ee4463ecd0d7de646fc39752dd499344073ce75f1
|
|
| MD5 |
8824ed7e5467828aada09807b605a6f2
|
|
| BLAKE2b-256 |
d2d98d0625ac6922c26da852109c5f4db4f81951950a6d4bea5fe98410d85b6b
|
File details
Details for the file lightgbm_feature_importance_evaluator_zhoumath-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lightgbm_feature_importance_evaluator_zhoumath-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ec57185a91d74bf72faea5ae94deec529b10f68b7e4ca54a4552935a7d713f5
|
|
| MD5 |
6766073bc897428ae9ccfdc4442cb0cd
|
|
| BLAKE2b-256 |
3aa61c2be02107802b8a544a7811658900c2abe2d62ae8f0cee0a89c2a9ef791
|