EpistasisLab / EpistasisLab/tpot

How to get the feature names from TPOT

Open
#1,070 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Jupyter Notebook
Stars
10.1k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

I started using Tpot after hearing about its efficiency in reducing the manual effort involved in identifying the right number of parameters.

So, I started with a simple task where my data has 4712 rows and 50 columns.

My pipeline looks like below

```
features = df_dummies.drop('flag', axis=1)
training_features, testing_features, training_target, testing_target = \
train_test_split(features, df_dummies['flag'], random_state=42)

# Average CV score on the training set was: 0.7992630100497694
exported_pipeline = make_pipeline(
make_union(
FunctionTransformer(copy),
RobustScaler()
),
RFE(estimator=ExtraTreesClassifier(criterion="entropy", max_features=0.15000000000000002, n_estimators=100), step=0.9500000000000001),
StackingEstimator(estimator=XGBClassifier(learning_rate=0.1, max_depth=2, min_child_weight=12, n_estimators=100, nthread=1, subsample=0.9000000000000001)),
DecisionTreeClassifier(criterion="entropy", max_depth=1, min_samples_leaf=15, min_samples_split=15)
)
# Fix random state for all the steps in exported pipeline
set_param_recursive(exported_pipeline.steps, 'random_state', 42)

exported_pipeline.fit(training_features, training_target)
results = exported_pipeline.predict(testing_features)
```
Now I would like to get the features used for arriving at this best score (after 2500 iterations).

So, I did the below

`ex_su = exported_pipeline.named_steps['rfe'].get_support()`

The above command returns boolean values for the feature.

I usually get the feature names using the columns list of the dataframe but when I tried the below, I got an error message
```
ex_fe = training_features.loc[:,ex_su].columns.tolist() # it doesn't work even if I use `features.loc[:,ex_su].columns.tolist()`
print(str((ex_fe)), 'Tpot selected features')
```

> IndexError: Item wrong length 98 instead of 49.

I understand that it says there is a length mismatch between my input (training_features) data frame and one used by TPOT. So, TPOT created new features? Because If that's the case, then we wouldn't be able to what those features are and how is it created? Is it Blackbox? I feel knowing the features that TPOT used to perform classification is very important and useful for people who are interested in interpretable model than a high performing model.

Can help me as to how we can get the feature names?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.