开始使用免费开始使用

使用管道

现在您已经定义好了管道,即将逻辑回归与 SMOTE 方法相结合,让我们在数据上运行它。您可以把这个管道当作一个单一的机器学习模型来使用。我们的数据 Xy 已经定义好,管道也在上一个练习中定义完成。想看看模型的结果吗?试试看吧!

本练习是课程的一部分

Python 中的欺诈检测

查看课程

练习说明

  • 将数据 Xy 划分为训练集和测试集。保留 30% 的数据作为测试集,并将 random_state 设为 0。
  • 在训练数据上拟合您的管道,并通过在 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)
编辑并运行代码