feature selection method with support for combined features
Project description
magic_selection
Feature selection method with support for combined features. You can combine features like ['Feature A', 'Feature B'] so that both of them will either be chosen or not
Installation
Conda environment using pip
conda create -n magic_selection python=3.9.12
conda activate magic_selection
conda install pip
pip install MagicSelection
Python3 virtual environment using pip
python3 -m venv env magic_selection
source magic_selection/bin/activate
pip install magic_selection
Conda environment from Github repository
git clone https://github.com/dwu12/feature_selection.git
cd magic_selection
pip install .
Usage
def magic_selection(df_train,
df_test,
score_metric,
model_dict,
target,
cv = 5,
upsample_flag = False,
upsample_flag_show = False,
ratio = 1,
random_state = 42,
replace = True ,
feature_groups = None,
fibe_cv = 3,
fibe_flag_show = False,
Threshold = None):
'''
test your feature selection model
Parameters
----------
df_train: training data
df_test: testing data
score_metric: classification metrics ('accuracy', 'f1', 'balanced_accuracy')
model_dict: a dictionary of model to be used
target: target value
cv = 5: default equal to 5 for cross-validation if df_test is None
upsamle_flag: if True, use upsample method, default False
upsample_flag_show: if True, show the target distribution, default False
Ratio: ratio of majority / minority, default is 1
random_state: for reproducible, default is 42
replace: sample with replacement or not, default is True
feature_groups: group features for better explanation. The idea is group one-hot encoder features together.
default is None
fibe_cv: cross validation with in FIBE method, default = 3
fibe_flag_show: print detail information, default = False
threshold: set a threshold for max # number of features you want select, default = None
----------
return offline metrics for either classification or regression as a dataframe
'''
Examples
from MagicSelection.feature_selection import magic_selection
from MagicSelection.feature_selection import get_example_data
df_outcome = get_example_data()
df_train = df_outcome[df_outcome['group'] == 'A'].drop(columns=['group'])
df_test = df_outcome[df_outcome['group'] == 'B'].drop(columns=['group'])
model_dic = {
'Decision Tree': tree.DecisionTreeClassifier(random_state = 11),
'SVM linear classifier' : SVC(kernel = 'linear',random_state = 11),
'SVM gaussian classifier' : SVC(random_state = 11)
}
feature_groups = [[i] for i in df_train.columns if i != 'Class']
result = magic_selection(df_train = df_train,
df_test = df_test,
model_dict = model_dic,
score_metric = 'accuracy',
target = 'Class',
feature_groups = feature_groups,
upsample_flag = True,
ratio = 1,
cv = 5)
display(result)
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
MagicSelection-0.0.17.tar.gz
(11.2 kB
view details)
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 MagicSelection-0.0.17.tar.gz.
File metadata
- Download URL: MagicSelection-0.0.17.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1fe114f564766a102cf57c6f106001aa9097ab397bddce6d193f3ce38d30d9a
|
|
| MD5 |
2da4b03272acd2a824895c2ef37c324c
|
|
| BLAKE2b-256 |
5ee180291c820beeb5bf76e6133aa325ad4436b6f9f7de4b0bd63f14cde6c97b
|
File details
Details for the file MagicSelection-0.0.17-py3-none-any.whl.
File metadata
- Download URL: MagicSelection-0.0.17-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df8860e8448a370d5c21ef0f542cca8f43f465045ec08c6fe6b632567138405e
|
|
| MD5 |
cd71b4bd6e9b3cea32dacc498c84a091
|
|
| BLAKE2b-256 |
83699a8256efa596a032da2f1c51b49249887199b26211efb3bfdf5edc99b6d9
|