Last active
November 14, 2021 18:41
-
-
Save jinhangjiang/fe0e7a4059aa845a9696bbda3223398e to your computer and use it in GitHub Desktop.
Voting Classifier in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load packages | |
from sklearn.ensemble import VotingClassifier | |
from sklearn.model_selection import cross_val_score, GridSearchCV | |
#fit a base model | |
vc = VotingClassifier([('dt', DecisionTree), | |
('KNN', KNN), | |
('MLPC', MLPC), | |
('rf', RandomForest), | |
('xgb', XGB)]) | |
cvm = cross_val_score(vc, X, y) | |
base_score = cvm.mean() | |
base_std = cvm.std() | |
print('\n') | |
print(f'The average base cross-validation score is {round(base_score,4)} (+- {round(base_std,4)})') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment