Hikaru's notes

A collection of notes and resources

View the Project on GitHub HikaruMizoe/notes

1.2 データを変換し、特徴量エンジニアリングを実行する

タスクステートメント

データを変換し、特徴量エンジニアリングを実行する

対象知識

データクリーニングおよびデータ変換の手法

特徴量エンジニアリング手法

エンコーディング手法

データと特徴量を調査、可視化、変換するためのツール

ストリーミングデータを変換するサービス

データアノテーションおよびラベリングサービス

対象スキル

1. AWS ツールを使用してデータを変換する

2. 特徴量の作成および管理

3. データの検証およびラベリング

実践例

Data Wranglerでのデータ変換

# One-Hot Encoding
from sagemaker.wrangler import DataWrangler

# 欠損値の処理
df.fillna(df.mean(), inplace=True)

# スケーリング
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
df_scaled = scaler.fit_transform(df)

Feature Storeの使用

from sagemaker.feature_store.feature_group import FeatureGroup

feature_group = FeatureGroup(
    name='customer-features',
    sagemaker_session=sagemaker_session
)

feature_group.load_feature_definitions(data_frame=df)
feature_group.create(
    s3_uri=f's3://{bucket}/feature-store',
    record_identifier_name='customer_id',
    event_time_feature_name='event_time',
    enable_online_store=True
)

Glue DataBrewでの変換

import boto3

client = boto3.client('databrew')

# レシピの作成
response = client.create_recipe(
    Name='data-cleaning-recipe',
    Steps=[
        {
            'Action': {
                'Operation': 'FILL_WITH_MODE',
                'Parameters': {
                    'sourceColumn': 'category'
                }
            }
        }
    ]
)

重要なポイント

エンコーディングの選択基準

| 手法 | 用途 | メリット | デメリット | |——|——|———-|————| | One-Hot | カテゴリ数が少ない | 解釈しやすい | 高次元になる | | Label | 順序あり | メモリ効率良い | 順序を暗示 | | Binary | カテゴリ数が多い | 次元削減 | 解釈が難しい |

スケーリングの選択基準

関連リンク