Skip to content

Instantly share code, notes, and snippets.

@jinhangjiang
Last active November 14, 2021 18:41
Show Gist options
  • Save jinhangjiang/fe0e7a4059aa845a9696bbda3223398e to your computer and use it in GitHub Desktop.
Save jinhangjiang/fe0e7a4059aa845a9696bbda3223398e to your computer and use it in GitHub Desktop.
Voting Classifier in Python
#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