A collection of notes and resources
モデリングアプローチを選択する
| 問題タイプ | 推奨アルゴリズム | 考慮事項 | |———–|—————-|———-| | 表形式データの分類・回帰 | XGBoost, Linear Learner | データサイズ、解釈可能性 | | 画像分類 | CNN, Image Classification | データ量、転移学習 | | テキスト分類 | BlazingText, Transformer | 文書長、言語 | | 時系列予測 | DeepAR, Prophet | 季節性、トレンド | | 異常検出 | Random Cut Forest | データ分布 |
from sagemaker import image_uris
from sagemaker.estimator import Estimator
# XGBoost アルゴリズムのイメージ URI を取得
container = image_uris.retrieve('xgboost', region, '1.7-1')
# Estimator の作成
xgb_estimator = Estimator(
container,
role=role,
instance_count=1,
instance_type='ml.m5.xlarge',
output_path=f's3://{bucket}/output',
sagemaker_session=session
)
# ハイパーパラメータの設定
xgb_estimator.set_hyperparameters(
objective='binary:logistic',
num_round=100,
max_depth=5,
eta=0.2
)
# トレーニング
xgb_estimator.fit({'train': s3_train_data})
from sagemaker.jumpstart.model import JumpStartModel
# 事前トレーニング済みモデルの選択
model_id = 'huggingface-text-classification-bert-base-uncased'
model = JumpStartModel(model_id=model_id)
# デプロイ
predictor = model.deploy()
# 推論
response = predictor.predict("This is a great product!")
import boto3
import json
bedrock = boto3.client('bedrock-runtime')
# Claude モデルを使用
response = bedrock.invoke_model(
modelId='anthropic.claude-v2',
body=json.dumps({
"prompt": "\\n\\nHuman: Explain machine learning\\n\\nAssistant:",
"max_tokens_to_sample": 300,
"temperature": 0.7
})
)
result = json.loads(response['body'].read())
print(result['completion'])
問題タイプの特定
├─ 画像データ?
│ ├─ Yes → CNN, Image Classification, Rekognition
│ └─ No → 次へ
├─ テキストデータ?
│ ├─ Yes → BlazingText, Transformers, Comprehend
│ └─ No → 次へ
├─ 時系列データ?
│ ├─ Yes → DeepAR, Forecast
│ └─ No → 次へ
└─ 表形式データ?
├─ 分類 → XGBoost, Linear Learner
└─ 回帰 → XGBoost, Linear Learner