モデルの学習

End-to-End Machine Learning

Joshua Stapleton

Machine Learning Engineer

オッカムの剃刀

  • 最も単純で十分な説明が最善
  • モデル選択はシンプル寄りに

オッカムの剃刀の原則を示す例の画像

End-to-End Machine Learning

モデルの選択肢

ロジスティック回帰

  • クラス間の境界を学習
  • sklearn.linear_model.LogisticRegression

サポートベクター分類器

  • クラスを分離する超平面を探索
  • sklearn.svm.SVC

決定木

  • 単純な「ルール」で分類
  • sklearn.tree.DecisionTreeClassifier

ランダムフォレスト

  • 複数の決定木をアンサンブル
  • sklearn.ensemble.RandomForestClassifier
End-to-End Machine Learning

その他のモデル

ディープラーニングモデル

  • ニューラルネットワーク
  • 畳み込みニューラルネットワーク
  • 生成系事前学習トランスフォーマー(GPT)

K-近傍法(KNN)

  • 教師あり学習アルゴリズム

XGBoost

End-to-End Machine Learning

学習の原則

モデル:

  • 前処理・特徴処理済みデータを使用
  • 訓練データのパターンを学習
  • 心疾患診断の目的変数を予測

原則:

  • 未知データ(訓練外)へ汎化すべき
  • 学習後の評価用に一部をホールドアウト
  • 訓練/テストは通常 70/30 または 80/20
  • sklearn.model_selection.train_test_split を使用可
End-to-End Machine Learning

モデルの学習手順

# Importing necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Split the data into training and testing sets (80:20) X_train, X_test, y_train, y_test = train_test_split(features, heart_disease_y, test_size=0.2, random_state=42)
# Define the models logistic_model = LogisticRegression(max_iter=200)
# Train the model logistic_model.fit(X_train, y_train)
End-to-End Machine Learning

予測の取得

# Jane Doe's health data, for example: [age, cholesterol level, blood pressure, etc.]
jane_doe_data = [45, 230, 120, ...]

# Reshape the data to 2D, because scikit-learn expects a 2D array-like input jane_doe_data = jane_doe_data.reshape(1, -1)
# Use the model to predict Jane's heart disease diagnosis probabilities jane_doe_probabilities = logistic_model.predict_proba(jane_doe_data) jane_doe_prediction = logistic_model.predict(jane_doe_data)
End-to-End Machine Learning

予測の取得(続き)

# Print the probabilities
print(f"Jane Doe's predicted probabilities: {jane_doe_probabilities[0]}")
print(f"Jane Doe's predicted health condition: {jane_doe_prediction[0]}")
Jane Doe's predicted health condition probabilities: [0.2 0.8]

Jane Doe's predicted health condition: 1
End-to-End Machine Learning

Passons à la pratique !

End-to-End Machine Learning

Preparing Video For Download...