Feature Selection : Filter Methods
각각의 독립변수를 하나만 사용한 예측모형의 성능을 이용하여 가장 분류성능 혹은 상관관계가 높은 변수만 선택하는 방법이다.
- 통계적 측정방법을 사용하여 피처들의 상관관계를 알아내는 방법
- 도움이 되지 않는 피처들은 걸러내는 'filter' 방식
💡하지만 단일 변수의 성능이 높은 특징만 모았을 때 전체 성능이 반드시 향상된다는 보장은 없다.
sklearn.feature_selection.SelectKBest
http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectKBest.html
■ parmamter
① scoring_func : 클래스 관련성 측정 함수
- chi2 (카이제곱 통계량) - 변수가 범주형이고 분류 문제
- f_calssif ( 분산분석(ANOVA) F 통계량 ) - 변수가 연속형이고 분류 문제
- f_regression ( F 통계량 ) : 변수가 연속형이고 라벨이 회귀 문제
- mutual_info_classif ( 상호정보량) : 변수가 연속/범주 형이고 라벨이 분류 문제
- mutual_info_regression ( 상호정보량) : 변수가 연속/범주 형이고 라벨이 회귀 문제
② k : 선택하는 특징 개수
■ 주요속성
① score_ : score_func 으로 측정한 특징별 점수
② pvalues_ : score_func으로 측정한 특징별 p-value
실행코드
연속형 변수와 범주형 변수가 있는 분류 문제에 대해 Feature Selection을 진행해보자.
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import mutual_info_classif
fs = SelectKBest(score_func=mutual_info_classif, k='all')
x_fs = fs.fit_transform(x, y)
# 시각화
plt.figure(figsize=(18, 8))
sns.barplot(x=x.columns, y=fs.scores_, orient='v')
plt.title('Feature Selection with mutual_info_classif')
plt.show()
pd.Series(fs.scores_ , index =x.columns).sort_values(ascending=False)
📊 시각화
'머신러닝(Machine Learning)' 카테고리의 다른 글
[불균형 데이터]오버샘플링(Over Sampling) (0) | 2023.11.29 |
---|