Computer Science/Concepts

FE - Feature Engineering

metamong 2022. 3. 22.

1. Concepts

* In real world, data is really messy - we need to clean the data

* FE = a process of extracting useful features from raw data using math, statistics and domain knowledge

- 즉, 도메인 지식과 창의성을 바탕으로 dataset에 존재하는 feature들을 재조합하여 새로운 feature를 만드는 과정이다

- 기존 feature끼리 재조합하여 새로운 열을 만들어내거나, 기존 feature에 조건식을 걸어 새로운 열을 만들어내기, 기존 열의 dtype 변환

- 분석의 결과, 모델링의 아웃풋 향상을 위해서 더 의미있는 패턴을 발견하기 위해 사용

- cleaning & organising data / collecting data sets에 많은 시간 소요

- to create features that make machine learning algorithms work

- when you use your knowledge about the data to select and create features that make machine learning algorithms work better.

 

👋 In summary, FE is simply using your existing knowledge of the dataset to create new features that can help a machine learning model perform better 👋

2. HOW?

→ using...

- domain knowledge) 도메인 지식을 통해 주어진 표의 feature들을 조합하여 새로운 feature들을 만들 수 있다.

- visualization) EDA과정에서 시각화로 나온 결과를 토대로 새로운 feature를 조합하는 아이디어를 생성할 수 있다. 

- math/statistics) EDA과정에서 사용한 수학/통계 기법의 결과를 토대로 역시 새로운 feature 생성이 가능하다

- including merge, group_by(using agg function)~ 

 

 ex) 기존의 feature들을 재조합하여 새로운 feature를 만드는 code

 

- 기존 df info

 

df.info()

 

더보기
더보기
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns (total 26 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   분기          5 non-null      object 
 1   매출액         5 non-null      int64  
 2   영업이익        5 non-null      int64  
 3   영업이익(발표기준)  5 non-null      float64
 4   세전계속사업이익    5 non-null      int64  
 5   당기순이익       5 non-null      int64  
 6   당기순이익(지배)   5 non-null      int64  
 7   당기순이익(비지배)  5 non-null      float64
 8   자산총계        5 non-null      int64  
 9   부채총계        5 non-null      int64  
 10  자본총계        5 non-null      int64  
 11  자본총계(지배)    5 non-null      int64  
 12  자본총계(비지배)   5 non-null      float64
 13  자본금         5 non-null      int64  
 14  영업활동현금흐름    5 non-null      int64  
 15  투자활동현금흐름    5 non-null      int64  
 16  재무활동현금흐름    5 non-null      int64  
 17  영업이익률       5 non-null      float64
 18  순이익률        5 non-null      float64
 19  ROE(%)      5 non-null      float64
 20  ROA(%)      5 non-null      float64
 21  부채비율        5 non-null      float64
 22  자본유보율       5 non-null      float64
 23  EPS(원)      5 non-null      int64  
 24  PER(배)      5 non-null      float64
 25  영업이익률2      5 non-null      float64
dtypes: float64(11), int64(14), object(1)
memory usage: 1.2+ KB

 

- 여기서 기존 df의 column '매출액'을 이용하여 경제 domain knowledge를 사용 새로운 column 'Relative Performance' feature를 만든다

 

df['Relative Performance'] = ((df['매출액'] - ~~~~ * 100) #보안상 ~~~ 물결표시로 code 생략

 

- df.info() 결과 26번째 column(feature)이 추가된 것을 볼 수 있다

 

더보기
더보기
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns (total 27 columns):
 #   Column                Non-Null Count  Dtype  
---  ------                --------------  -----  
 0   분기                    5 non-null      object 
 1   매출액                   5 non-null      int64  
 2   영업이익                  5 non-null      int64  
 3   영업이익(발표기준)            5 non-null      float64
 4   세전계속사업이익              5 non-null      int64  
 5   당기순이익                 5 non-null      int64  
 6   당기순이익(지배)             5 non-null      int64  
 7   당기순이익(비지배)            5 non-null      float64
 8   자산총계                  5 non-null      int64  
 9   부채총계                  5 non-null      int64  
 10  자본총계                  5 non-null      int64  
 11  자본총계(지배)              5 non-null      int64  
 12  자본총계(비지배)             5 non-null      float64
 13  자본금                   5 non-null      int64  
 14  영업활동현금흐름              5 non-null      int64  
 15  투자활동현금흐름              5 non-null      int64  
 16  재무활동현금흐름              5 non-null      int64  
 17  영업이익률                 5 non-null      float64
 18  순이익률                  5 non-null      float64
 19  ROE(%)                5 non-null      float64
 20  ROA(%)                5 non-null      float64
 21  부채비율                  5 non-null      float64
 22  자본유보율                 5 non-null      float64
 23  EPS(원)                5 non-null      int64  
 24  PER(배)                5 non-null      float64
 25  영업이익률2                5 non-null      float64
 26  Relative Performance  5 non-null      float64
dtypes: float64(12), int64(14), object(1)
memory usage: 1.2+ KB

 

3. Feature Engineering is.....

Q) so it is quite a tough job

A) a vital component of modelling process, and it is the toughest to automate. It takes domain expertise and a lot of exploratory analysis on the data to engineer features

 

Q) w/ feature selection?

A) Better features means flexibility, simpler models, better results. Presence of irrelevant features hurt generalization. Thus feature selection and feature engineering should not be considered as mutually exclusive activities and should be performed in conjunction to each other. With the help of an effective feature engineering process, we intend to come up with an effective representation of the data.

(후에 여러 feature selection 기법을 배울 건데 앞서 배운 FE와 서로 별개의 기법이라 생각하지 말고 같이 쓸 수 있는 절차라 생각하면 될 듯하다!)

 

** poke the given dataset, tear it apart, find the hidden gems and derive insights from it, and also have fun while at it 😆


* 출처1) https://towardsdatascience.com/exploratory-data-analysis-feature-engineering-and-modelling-using-supermarket-sales-data-part-1-228140f89298 

* 출처2) https://www.datasciencecentral.com/feature-engineering-data-scientist-s-secret-sauce-1/ 

'Computer Science > Concepts' 카테고리의 다른 글

Tidy Data  (0) 2022.04.13
REST API example - Coingecko API  (0) 2022.03.30
Tabular Data 🗄️  (0) 2022.03.26
Data Preprocessing  (0) 2022.03.25
EDA - Exploratory Data Analysis  (0) 2022.03.22

댓글