A collection of notes and resources
データを変換し、特徴量エンジニアリングを実行する
# 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)
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
)
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 | カテゴリ数が多い | 次元削減 | 解釈が難しい |