PYTHON/Python

Python 머신러닝 피처 엔지니어링(Feature Enginerring) 개념 기초 정리

진리뷰 2024. 4. 4. 09:00
반응형

 

 

 

Python-머신러닝-피처-엔지니어링(Feature-Enginerring)-개념-기초-정리-썸네일
피처 엔지니어링(Feature Enginerring)

 

 

 

이 글은 머신러닝 피처 엔지니어링(Feature Enginerring) 개념과 방법 기초 정리를 담고 있습니다.

 

 

 

Python 피처 엔지니어링(Feature Enginerring) 개념

 

  • 특성 공학으로도 불림.
  • 알고리즘(모델) 성능 향상을 위해, 원본으로부터 Feature(x, 독립 변수)를 (재)구성.
  • 테이블의 기존 컬럼을 바탕으로 새 컬럼 추가 혹은 컬럼 제거.
  • 타깃 변수와 의미 있는 변수를 선택하는 과정.
  • 때문에 데이터 도메인 지식, 즉 전문성이 많이 필요한 과정이다.

ML work flow (출처: https://www.mdpi.com/2073-4395/10/12/1926)

 

 

 

Python 피처 엔지니어링(Feater Enginerring) 방법

 

피처 엔지니어링에는 여러 방법이 있는데, 그중 몇 가지만 추려보자.

 

 

Feature Encoding

 

모델 학습을 위해 모델에 맞는 Feature로 변환.

범주형 변수(문자)를 연속형 변수(숫자)로 변환하거나, 이미 연속형 변수지만 모델 성능 향상을 위해 다른 연속형 변수로 변환.

이에는 레이블 인코딩(Label Encoding), 원-핫 인코딩(One-Hot Encoding) 방식이 주로 사용됨.

 

  • 레이블 인코딩(Label Encoding)

레이블 인코딩은  sklearn의 LabelEncoder를 사용하여, 범주형 변수를 연속형 변수로 일대일 매핑 하는 방식이다.

예를 들어, Group 컬럼에서 문자형인 A, B, C 세 그룹은 레이블 인코딩 방식을 거쳐 0(A), 1(B), 2(C)로 변환됨.

 

Label Encoding
Group 👉 Group
A 0
B 1
C 2

 

  • 원-핫 인코딩(One-Hot Encoding)

원-핫 인코딩은 하나(One)만 활성화(Hot) 한다는 의미로, 숫자 0과 1을 사용하는 방식.

기존 Feature의 고윳값을 새 컬럼으로 추가 후, 해당 컬럼과 일치하는 값은 1, 불일치하는 값은 0으로 표현한다.

쉽게 말해, 행이었던 Feature를 열로 변환해서 0, 1로 표현.

이때 원-핫 인코딩을 진행하려면, 레이블 인코딩을 선 진행해야 한다.

 

One-Hot Encoding
Group 👉


A B C
A 1 0 0
B 0 1 0
C 0 0 1
A 1 0 0
C 0 0 1

 

 

 

Feature Extraction & Feature Selection

 

과적합 방지나 빠른 계산 등 모델의 성능 향상을 위해, 높은 관련성 and 저차원 등을 목표로 차원 축소를 진행한다.

이와 관련 개념으로는 Feature Extraction과 Feature Selection이 있다.

 

  • Feature Extraction

원본 Feature를 모두 활용, 조합하여 유용하고 새로운 Feature로 "생성".

때문에 원본 Feature를 확인하기 어렵다.

이에는 PCA, LDA, PLS 방식을 주로 사용하며, 분류 / 회귀 / 군집화 문제에 자주 사용한다.

 

Machine-Learning-Feature-Extraction
출처: https://www.i2tutorials.com/what-is-the-difference-between-feature-selection-and-feature-extraction/

 

 

 

Feature Selection

 

원본 Feature에서 무의미한 Feature를 제거하며, 높은 관련성을 가진 부분 집합(Subset)을 "선택"한다.

Feature Extraction과 달리, 원본 Feature를 유지한다는 점에서 모델 해석이 가능하다.

 

machine-learning-feature-selection
출처: https://www.i2tutorials.com/what-is-the-difference-between-feature-selection-and-feature-extraction/

 

 

이에는 아래와 같은 방식들이 사용된다.

 

Feature-Selection-Techniques
출처: https://www.javatpoint.com/feature-selection-techniques-in-machine-learning

 

 


 

 

관련 글 추천

1. What is the difference between Feature Selection and Feature Extraction?

 

What is the difference between Feature Selection and Feature Extraction? | i2tutorials

Feature selection is the process of choosing precise features, from a features pool. This helps in simplification, regularization and shortening training time. This can be done with various techniques: e.g. Linear Regression, Decision Trees.

www.i2tutorials.com

 

 

2. Feature Selection vs Feature Extraction: Machine Learning

 

Feature Selection vs Feature Extraction: Machine Learning - Analytics Yogi

Feature Selection, Feature Extraction, Features Engineering, Data Science, Machine Learning, Python, R, Tutorials, Tests, Interviews, News, AI

vitalflux.com

 

반응형
top