开始使用免费开始使用

Adjust weights within the Voting Classifier

You've just seen that the Voting Classifier allows you to improve your fraud detection performance, by combining good aspects from multiple models. Now let's try to adjust the weights we give to these models. By increasing or decreasing weights you can play with how much emphasis you give to a particular model relative to the rest. This comes in handy when a certain model has overall better performance than the rest, but you still want to combine aspects of the others to further improve your results.

For this exercise the data is already split into a training and test set, and clf1, clf2 and clf3 are available and defined as before, i.e. they are the Logistic Regression, the Random Forest model and the Decision Tree respectively.

本练习是课程的一部分

Fraud Detection in Python

查看课程

练习说明

  • Define an ensemble method where you over weigh the second classifier (clf2) with 4 to 1 to the rest of the classifiers.
  • Fit the model to the training and test set, and obtain the predictions predicted from the ensemble model.
  • Print the performance metrics, this is ready for you to run.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Define the ensemble model
ensemble_model = ____(estimators=[('lr', clf1), ('rf', clf2), ('gnb', clf3)], voting='soft', weights=[____, ____, ____], flatten_transform=True)

# Get results 
get_model_results(X_train, y_train, X_test, y_test, ensemble_model)
编辑并运行代码