Permutation Importance
내부를 잘 알지 못하는(Black-box) ML model이 있을때, 그 model 내부에서 각 feature가 prediction에 얼만큼의 영향을 끼치는지에 대한 지표인 feature importance라고 하고 이는 수학적으로 해당 모델에서 각 feature와 target이 가지는 상관관계 크기를 의미한다.
기본 원리
특정 feature의 value들만 무작위로 섞은 shuffled validation dataset을 만들고
기존 validation dataset과 비교했을때 prediction accuracy가 얼만큼 차이나는지
비교한다.
shuffled validation dataset에서 :
- prediction accuracy가 많이 낮아질수록 높은 feature importance를 가진다.
![]() |
좌 : non-shuffled, 우 : shuffled, accuracy의 변화가 뚜렸하다 |
- prediction accuracy의 변화가 적을수록 낮은 feature importance를 가진다.
![]() |
좌 : non-shuffled, 우 : shuffled, 위쪽 예시에 비해 accuracy에 큰 변화가 없다. |
왜 이름이 Permutation Importance일까?
어떤 feature의 feature importance를 알아내기위해 여러가지 shuffled validation data
set을 만드는일은 해당 feature value의 여러가지 permutation을 만드는 과정으로
볼 수 있다.
장점
- 별도의 재학습(re-training)과정이 필요가 없어서 빠르다. 학습은 예측보다 시간이 훨신 많이 걸린다.
단점
- under or over-fitting된 model에 대해서는 model의 feature importance가 실제 feature-target간의 상관관계와는 상이할 수 있다. 언제까지나 model에 종속적인 속성임을 알아야한다.
- 각 feature들이 모두 독립변수라는 가정을 한다. 이는 Model들이 실제로 그런 가정을 기반으로 학습되기 때문이기도 하다. 때문에 실제 dataset에서는 feature들간의 상관관계가 존재함에 따라 target과의 상관관계가 다를 수 있다.
구현
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eli5 | |
from eli5.sklearn import PermutationImportance | |
#model 이미 train이 끝난 모델 | |
perm = PermutationImportance(model).fit(val_X, val_y) | |
#각 feature들의 weight를 출력 | |
eli5.show_weights(perm, feature_names = val_X.columns.tolist()) |
댓글
댓글 쓰기