FRUFS: Feature Relevance based Unsupervised Feature Selection
FRUFS stands for Feature Relevance based Unsupervised Feature Selection and is an unsupervised feature selection technique that uses supervised algorithms such as XGBoost to rank features based on their importance. The entire algorithm is explained in the following blog
How to install?
pip install FRUFS
Functions and parameters
# The initialization of FRUFS takes in multiple parameters as input
model = FRUFS(model_r, model_c, k, n_jobs, verbose, categorical_features, random_state)
- model_r -
estimator object, default=DecisionTreeRegressor()The model which is used to regress current continuous feature given all other features. - model_c -
estimator object, default=DecisionTreeClassifier()The model which is used to classify current categorical feature given all other features. - k -
float/int, default=1.0The number of features to select.floatmeans to considerround(total_features*k)number of features. Values range from0.0-1.0intmeans to considerknumber of features. Values range from0-total_features
- n_jobs -
int, default=-1The number of CPUs to use to do the computation.Nonemeans 1 unless in a:obj:joblib.parallel_backendcontext.-1means using all processors.
- verbose -
int, default=0Controls the verbosity: the higher, more the messages. A value of 0 displays a nice progress bar. - categorical_features -
list of integers or stringsA list of indices denoting which features are categoricallist of integersIf input data is a numpy matrix then pass a list of integers that denote indices of categorical featureslist of stringsIf input data is a pandas dataframe then pass a list of strings that denote names of categorical features
- random_state -
int or RandomState instance, default=NonePass an int for reproducible output across multiple function calls.
# To fit FRUFS on provided dataset and find recommended features
fit(data)
- data - A pandas dataframe or a numpy matrix upon which feature selection is to be applied
(Passing pandas dataframe allows using correct column names. Numpy matrix will apply default column names)
# This function prunes the dataset to selected set of features
transform(data)
- data - A pandas dataframe or a numpy matrix which needs to be pruned
(Passing pandas dataframe allows using correct column names. Numpy matrix will apply default column names)
# To fit FRUFS on provided dataset and return pruned data
fit_transform(data)
- data - A pandas dataframe or numpy matrix upon which feature selection is to be applied
(Passing pandas dataframe allows using correct column names. Numpy matrix will apply default column names)
# To plot XGBoost style feature importance
feature_importance()
How to import?
from FRUFS import FRUFS
Usage
If data is a pandas dataframe
# Import the algorithm.
from FRUFS import FRUFS
# Initialize the FRUFS object
model_frufs = FRUFS(model_r=LGBMRegressor(random_state=27), model_c=LGBMClassifier(random_state=27, class_weight="balanced"), categorical_features=categorical_features, k=13, n_jobs=-1, verbose=0, random_state=27)
# The fit_transform function is a wrapper for the fit and transform functions, individually.
# The fit function ranks the features and the transform function prunes the dataset to selected set of features
df_train_pruned = model_frufs.fit_transform(df_train)
df_test_pruned = model_frufs.transform(df_test)
# Get a plot of the feature importance scores
model_frufs.feature_importance()
If data is a numpy matrix
# Import the algorithm.
from FRUFS import FRUFS
# Initialize the FRUFS object
model_frufs = FRUFS(model_r=LGBMRegressor(random_state=27), model_c=LGBMClassifier(random_state=27, class_weight="balanced"), categorical_features=categorical_features, k=13, n_jobs=-1, verbose=0, random_state=27)
# The fit_transform function is a wrapper for the fit and transform functions, individually.
# The fit function ranks the features and the transform function prunes the dataset to selected set of features
X_train_pruned = model_frufs.fit_transform(X_train)
X_test_pruned = model_frufs.transform(X_test)
# Get a plot of the feature importance scores
model_frufs.feature_importance()
For better accuracy
- Try incorporating more features by increasing the value of k
- Pass strong, hyperparameter-optimized non-linear models
For better speeds
- Set n_jobs to -1
Performance in terms of Accuracy (classification) and MSE (regression)
| Dataset | # of samples | # of features | Task Type | Score using all features | Score using FRUFS | # of features selected | % of features selected | Tutorial |
|---|---|---|---|---|---|---|---|---|
| Ionosphere | 351 | 34 | Supervised | 88.01 | 91.45 | 24 | 70.5% | tutorial here |
| Adult | 45222 | 14 | Supervised | 62.16 | 62.65 | 13 | 92.8% | tutorial here |
| MNIST | 60000 | 784 | Unsupervised | 50.48 | 53.70 | 329 | 42.0% | tutorial here |
| Waveform | 5000 | 21 | Unsupervised | 38.20 | 39.67 | 15 | 72.0% | tutorial here |
Note: Here, for the first and second task, we use accuracy and f1 score, respectively while for both the fourth and fifth tasks, we use the NMI metric. In all cases, higher scores indicate better performance.
Future Ideas
- Let me know
Feature Request
Drop me an email at atif.hit.hassan@gmail.com if you want any particular feature
Metadata
Release files for FRUFS 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| FRUFS-1.0.3.tar.gz | 6.1 kB | Without provenance | Details for FRUFS-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| FRUFS-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for FRUFS-1.0.3-py3-none-any.whl |
Total release size: 12.0 kB
Release files / FRUFS-1.0.3.tar.gz
| Download URL | FRUFS-1.0.3.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a4100879637104a9dce6a6290d16fe373e3f584d848ea33c89550469fe9a97f
|
|
BLAKE2b-256 checksum How to use checksums |
1ca56ebf8dd238ced0be92242726fec90fcceafb357caeb3437375058f7f1090
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / FRUFS-1.0.3-py3-none-any.whl
| Download URL | FRUFS-1.0.3-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82ee381cf54a5737e87bfc513ca6cc172d09852dffe68477c4dc225caa336476
|
|
BLAKE2b-256 checksum How to use checksums |
7ba918b88a6f855220c3d0d012bd0393a30f852a301843dd7aeb3a33352342d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Security for FRUFS 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.