특성 공학

프로덕션을 위한 Machine Learning 모델 개발

Sinan Ozdemir

Data Scientist and Author

특성 공학 소개

  • ML 파이프라인 성능을 극대화하기 위한 훈련 데이터 변환
  • 연산 복잡도 감소
  • 예시
    • 여러 출처의 데이터 집계
    • 새로운 특성 생성
    • 특성 변환 적용

특성 공학 파이프라인

1 https://www.manning.com/books/feature-engineering-bookcamp
프로덕션을 위한 Machine Learning 모델 개발

여러 출처의 데이터 집계

  • 서로 다른 데이터셋 결합
  • 여러 유형의 데이터 활용(예: 수치형과 범주형)

다음과 같은 효과가 있습니다:

  • 모델 정확도 향상
  • 더 복잡한 모델 사용 가능

화면에 표시된 그래프

프로덕션을 위한 Machine Learning 모델 개발

데이터 집계 예시

class DataAggregator:
    def __init__(self):
        pass

    def fit(self, X, y=None):
        return self  # nothing to fit

    def transform(self, X, y=None):
        # Load data from multiple sources
        data1 = pd.read_csv('data1.csv')
        data2 = pd.read_csv('data2.csv')
        data3 = pd.read_csv('data3.csv')

        # Combine data from all sources (including X) into a single data frame
        aggregated_data = pd.concat([X, data1, data2, data3], axis=0)

        return aggregated_data  # Return aggregated data
프로덕션을 위한 Machine Learning 모델 개발

특성 생성

  • 기존 특성을 바탕으로 새로운 특성 생성
  • 기존 데이터로부터 새로운 특성 생성
  • 모델 성능 향상
  • 모델 해석력 향상
프로덕션을 위한 Machine Learning 모델 개발

특성 생성 예시

class FeatureConstructor:
    def __init__(self):
        pass

    def fit(self, X, y=None):
        return self

    def transform(self, X, y=None):
        # Calculate the mean of each column in the data
        mean_values = X.mean()

        # Create new features based on the mean values
        X['mean_col1'] = X['col1'] - mean_values['col1']
        X['mean_col2'] = X['col2'] - mean_values['col2']

        return X  # Return the augmented data set
프로덕션을 위한 Machine Learning 모델 개발

특성 변환

기존 특성을 그대로 변환

  • 데이터 분포 정규화
  • 이상치 제거
  • 모델 정확도와 성능 향상
```py
```py

프로덕션을 위한 Machine Learning 모델 개발

특성 선택

중복되거나 관련 없는 특성을 제거해 더 큰 특성 집합에서 일부를 선택하는 과정

  • 과적합 감소
  • 모델 정확도와 성능 향상
  • 모델 해석력 향상

특성 선택

1 https://www.manning.com/books/feature-engineering-bookcamp
프로덕션을 위한 Machine Learning 모델 개발

특성 공학 예시(계속)

```py
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.feature_selection import SelectKBest, chi2

from sklearn.pipeline import Pipeline

pipeline = Pipeline([  # Define feature engineering pipeline

    ('aggregate', DataAggregator()),  # Aggregate data from multiple sources
    ('construction', FeatureConstructor()),  # Feature Construction

    ('scaler', StandardScaler()),  # Feature Transformation

    ('select', SelectKBest(chi2, k=10)),  # Feature Selection
])
X_transformed = pipeline.fit_transform(X)  # Fit and transform data using pipeline
프로덕션을 위한 Machine Learning 모델 개발

특성 공학에 대해 더 알아보기

특성 공학 책

프로덕션을 위한 Machine Learning 모델 개발

연습해 봅시다!

프로덕션을 위한 Machine Learning 모델 개발

Preparing Video For Download...