我正在使用来自的确切示例SciKit https://scikit-learn.org/stable/auto_examples/inspection/plot_permutation_importance.html#sphx-glr-auto-examples-inspection-plot-permutation-importance-py,比较permutation_importance
with tree feature_importances
如您所见,使用了 Pipeline:
rf = Pipeline([
('preprocess', preprocessing),
('classifier', RandomForestClassifier(random_state=42))
])
rf.fit(X_train, y_train)
permutation_importance
:
现在,当您安装Pipeline
, 它会依次拟合所有变换并变换数据,然后使用最终估计器拟合变换后的数据。
在后面的例子中,他们使用了permutation_importance
在拟合模型上:
result = permutation_importance(rf, X_test, y_test, n_repeats=10,
random_state=42, n_jobs=2)
Problem:我不明白的是,其中的功能result
仍然是原始的未转换的特征。为什么会这样呢?这工作正常吗?目的是什么Pipeline
then?
tree feature_importance
:
在同一个例子中,当他们使用feature_importance
,结果变换为:
tree_feature_importances = (
rf.named_steps['classifier'].feature_importances_)
我显然可以改变我的功能,然后使用permutation_importance
,但示例中提出的步骤似乎是故意的,并且应该有一个原因permutation_importance
不改变特征。