Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tune weights in Voting Classifier (Sklearn)

I am trying to do the following:

vc = VotingClassifier(estimators=[('gbc',GradientBoostingClassifier()),
                       ('rf',RandomForestClassifier()),('svc',SVC(probability=True))],
                       voting='soft',n_jobs=-1)

params = {'weights':[[1,2,3],[2,1,3],[3,2,1]]}
grid_Search = GridSearchCV(param_grid = params, estimator=vc)
grid_Search.fit(X_new,y)
print(grid_Search.best_Score_)

In this, I want to tune the parameter weights. If I use GridSearchCV, it is taking a lot of time. Since it needs to fit the model for each iteration. Which is not required, I guess. Better would be use something like prefit used in SelectModelFrom function from sklearn.model_selection.

Is there any other option or I am misinterpreting something?

like image 705
Abhinav Gupta Avatar asked Oct 29 '22 00:10

Abhinav Gupta


1 Answers

The following code (in my repo) would do this.

It contains a class VotingClassifierCV. It first makes cross-validated predictions for all classifiers. Then loops over all weights, choosing the best combination, and using pre-calculated predictions.

like image 184
David Dale Avatar answered Jan 08 '23 03:01

David Dale