始める無料で始める

パイプラインを使う

すでに定義したパイプライン、つまり ロジスティック回帰と SMOTE 手法の組み合わせ をデータで動かしてみましょう。パイプラインは 1つの Machine Learning モデル と同じように扱えます。データ Xy はすでに用意されており、パイプラインは前の演習で定義済みです。モデルの結果がどうなるか気になりますよね。さっそく試してみましょう!

この演習はコースの一部です

Pythonで学ぶ不正検知

コースを見る

演習の手順

  • データ Xy を学習用とテスト用に分割します。テストデータは全体の30%を確保し、random_state は 0 に設定してください。
  • 学習データでパイプラインを学習させ、pipeline.predict()X_test に対して実行して予測値を取得します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Split your data X and y, into a training and a test set and fit the pipeline onto the training data
X_train, X_test, y_train, y_test = ____

# Fit your pipeline onto your training set and obtain predictions by fitting the model onto the test data 
pipeline.fit(____, ____) 
predicted = pipeline.____(____)

# Obtain the results from the classification report and confusion matrix 
print('Classifcation report:\n', classification_report(y_test, predicted))
conf_mat = confusion_matrix(y_true=y_test, y_pred=predicted)
print('Confusion matrix:\n', conf_mat)
コードを編集して実行