【发布时间】:2020-03-19 19:23:39
【问题描述】:
尝试使用 BorutaPy 进行特征选择。但是得到一个 TypeError: '(slice(None, None, None), array([0, 1, 2, 3, 4]))' 是一个无效的键。
from sklearn.ensemble import RandomForestClassifier
from boruta import BorutaPy
rf = RandomForestClassifier(n_jobs=-1, max_depth=4)
# define Boruta feature selection method
feat_selector = BorutaPy(rf, n_estimators='auto', verbose=2, random_state=1)
X = train_dt[['age', 'menopause', 'tumor_size', 'inv_nodes', 'node_caps',
'deg_malig', 'breast', 'breast_quad', 'irradiat']]
Y = train_dt.label
# find all relevant features - 5 features should be selected
feat_selector.fit(x, y)
# check selected features - first 5 features are selected
feat_selector.support_
# check ranking of features
feat_selector.ranking_
# call transform() on X to filter it down to selected features
X_filtered = feat_selector.transform(X)
我使用了乳腺癌 dataset 并进行了一些小的调整,例如添加标题、特征缩放和缺失值处理。
【问题讨论】:
-
你在哪一行得到错误?
标签: python machine-learning feature-extraction feature-selection