1、引入头文件
from xgboost.sklearn import XGBClassifier
from lightgbm.sklearn import LGBMClassifier
from catboost import CatBoostClassifier
from sklearn.ensemble import VotingClassifier

2、编写分类器

1)LGBMClassifier

lgb_clf = LGBMClassifier(
                    n_jobs=-1, 
                    device_type='gpu',
                    n_estimators=400,
                    learning_rate=0.1,
                    max_depth=7,
                    num_leaves=31,
                    colsample_bytree=0.8,
                    subsample=0.6,
                    # max_bins=127,
                ),                        

2)XGBoost

xgb_clf= XGBClassifier(random_state=2020, n_jobs=-1,verbose=0,
                     n_estimators = 500,
                     learning_rate = 0.1,
                     max_depth=8,
                     colsample_bytree = 0.9, 
                     subsample=0.8, 
                     reg_alpha = 0.8,
                     reg_lambda = 4,
                     tree_method='gpu_hist',gpu_id=0,
                 ),

3)Cat_Boost

cat_clf = CatBoostClassifier(
            thread_count=-1,
            verbose=0,
            iterations=5000,
            learning_rate=0.1,
            depth=6,
            l2_leaf_reg=1,
            border_count=254,
            task_type='GPU',
        )

3、Voting分类器

1)创建分类器

vt_clf=VotingClassifier(estimators=[
    ('lgb_clf',lgb_clf),
    ('xgb_clf', xgb_clf),
    ('cgb_clf',cat_clf),
], voting = 'hard' )
2)拟合
vt_clf.fit(x_train,y_train)
3)预测
pred=vt_clf.predict(x_test)
print("准确率为:",np.mean(pred==y_test))