Feature election group of classes calculate the importance of features based on the Shap library for the classification and regression problem Only works with randomforest models for efficiency or gradient boosting models. DFwrapper - remove multicollinearity and outliers
Project description
Library consist of two groups of Classes - Feature selectors and DFwrapper to have a deal with outliers and correlation
- Feature selection group
The FeatureSelection calculates the importance of features based on the Shap library for a classification problem.
Only works with trees for better efficiency or models based on
gradient boosting. It is a priority to use such models as:
Catboost - does not require handling of NaN and categories. works with sklearn
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
!pip install shap
!pip install phik
https://pypi.org/project/SHFS/
FeatureSelectionClf - for classification
FeatureSelectionRegression - for regression
FeatureSelectionUniversal - for both classification and regression tasks
Quick start: Collab and Tutorial
Parametrs.
`estimator` :
Supervised learning with the fit method will allow you to retrieve and select indices.
the most important features.
n_features_to_select: int, default = None.
The number of features to select, the default is None.
columns: List, default = None.
The list of attributes of the initial set, the default is None.
Methods
fit - trains and identifies the most important features
tranform - changes the original set and returns the selected attributes
get_index - Returns the selected indexes attributes
only for FeatureSelectionClf and FeatureSelectionRegression:
plot_values - plotting shap values
_estimator_type - @property method
get_feature_importance - Returns DataFrame FI
Note
Nan / Inf are allowed in case they are accepted by the fit method model Example use for classification
cols = list(X_train.columns)
cat_features = list(X_train_cat.select_dtypes(include=['object', 'category']).columns)
num_features = list(X_train_cat.select_dtypes(exclude=['object', 'category']).columns)
estimator = CatBoostClassifier(**params_cat)
selector = FeatureSelectionClf(estimator, n_features_to_select=3, columns=cols)
preprocessor = ColumnTransformer (
transformers = [
('std_scaler' , StandardScaler() , num_features) ,
('cat' , OrdinalEncoder() , cat_features),
]
)
pipe = Pipeline(steps=
[
('preprocessor', preprocessor),
('selector', selector)
]
)
X_train_prep = pipe.fit_transform(X_train)
Example without Pipeline
cols = list(X_train.columns)
estimator = CatBoostClassifier(**params_cat)
selector = FeatureSelectionClf(estimator, n_features_to_select=3, columns=cols)
X = selector.fit(X_train_prep, y_train)
- DFwrapper
DFwrapper - remove multicollinearity and outliers from Pandas DataFrame
Usage example
----------
1. Collinearity
cleaner = DFwrapper()
new_df = cleaner.wrap_corr(df)
2. Outliers. Rough cleaning
cleaner = DFwrapper(low=.05, high=.95)
cleaned = cleaner.quantile_cleaner(df, cols_to_clean)
2. Outliers. Finer cleaning
cleaner = DFwrapper(koeff=1.5)
cleaned = cleaner.frame_irq(df, cols_to_clean)
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 SHFS-0.1.5.tar.gz.
File metadata
- Download URL: SHFS-0.1.5.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.8.1 requests/2.26.0 setuptools/58.3.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8187be4fbab247812c8f4a87c5f317a1e82c4762981015ca65409491257992e1
|
|
| MD5 |
fbb4104bcbc34e2e8d8f7d92b479e799
|
|
| BLAKE2b-256 |
07c3fc067196c2830990dbcbd609d8860e01bc82dc965e3ed86791560f6ede9d
|
File details
Details for the file SHFS-0.1.5-py3-none-any.whl.
File metadata
- Download URL: SHFS-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.8.1 requests/2.26.0 setuptools/58.3.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42b0e03007f0899e68ec5bedb9eb9dc041444106de92283ba4ed2141f4050cd1
|
|
| MD5 |
ff47c3bc577d188e621b7d654d73ab6b
|
|
| BLAKE2b-256 |
150fb69c763857bcd12c74bc557dd8c4a45ad082607db0ff66cd8098c3eb3a5a
|