使用 pipeline
現在你已經定義好 pipeline,也就是將羅吉斯迴歸與 SMOTE 方法結合,來把它跑在資料上吧。你可以把這個 pipeline 視為單一的機器學習模型來使用。我們的資料 X 和 y 已經準備好,且 pipeline 已在前一題中定義。想看看模型的結果嗎?試試看吧!
本練習屬於課程
Fraud Detection in Python
練習說明
- 將資料
X和y分成訓練集與測試集。保留 30% 的資料作為測試集,並將random_state設為 0。 - 將你的 pipeline 套用在訓練資料上並完成訓練,接著在
X_test資料集上執行pipeline.predict()以取得預測結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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)