[Feature Selection] Permutation Importance

순열중요도

- 예측에 가장 영향을 미치는 피쳐를 파악하기 위해 사용.

 

모델 피팅 후 활용

 

- 한번에 한 개의 특성 값을 무작위로 섞어 특성와 실제 결과 사이의 관계를 없애고 모델의 예측 오차 증가를 측정하여 특성의 중요도를 판단

- 특성 값을 섞었을 때 모델 오류가 증가하는 경우 : 예측에 중요한 피쳐

 

- 중요한 특성 파악하여 모델 학습

- 학습 모델을 설명할 때 활용

 

import eli5 
from eli5.sklearn import PermutationImportance
from sklearn.ensemble import RandomForestRegressor

rf = RandomForestRegressor(bootstrap=True, ccp_alpha=0.0, criterion='mae',
                      max_depth=30, max_features=6, max_leaf_nodes=None,
                      max_samples=None, min_impurity_decrease=0.0,
                      min_impurity_split=None, min_samples_leaf=8,
                      min_samples_split=16, min_weight_fraction_leaf=0.0,
                      n_estimators=100, n_jobs=None, oob_score=False,
                      random_state=None, verbose=0, warm_start=False)
# model fitting
rf.fit(X_train,y2_train)

# Permutation Importance
permutation = PermutationImportance(rf, scoring = "neg_mean_absolute_error", random_state = 42).fit(X_test, y2_test) 
eli5.show_weights(permutation, feature_names = train1.drop(['ln','dn','day','season'], axis=1).columns.tolist())

 

 

 

 

 

 


Source

https://www.kaggle.com/dansbecker/permutation-importance