尝试使用 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 …Run Code Online (Sandbox Code Playgroud) python machine-learning feature-extraction feature-selection