xgboost 0.8 GPU training by python API

这篇博客介绍了如何利用xgboost 0.8版本的Python API进行GPU训练,特别是支持NVIDIA GPU的gpu_exact和gpu_hist算法。虽然目前不支持多GPU训练,但单GPU训练已经足够。文章提到了启用GPU训练需要设置的参数,如'tree_method': 'gpu_hist', 'predictor': 'gpu_predictor',并提供了修改自官方教程的示例。" 124934462,10801487,Flutter JSON解析与序列化指南,"['Flutter开发', 'JSON处理', '数据解析', '序列化工具', '编程实践']
摘要由CSDN通过智能技术生成

The binary wheel will support GPU algorithms (gpu_exact, gpu_hist) on machines with NVIDIA GPUs. However, it will not support multi-GPU training; only single GPU will be used [Installation Guide]
For the moment, single gpu is enought for me

pip install xgboost

To enable gpu training, some parameter must pass when constructed i.e. params = {‘tree_method’: ‘gpu_hist’, ‘predictor’: ‘gpu_predictor’}, below is an example modified from [
Tune Learning Rate for Gradient Boosting with XGBoost in Python]

import pickle
import xgboost as xgb
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from sklearn.model_selection import StratifiedKFold, GridSearchCV

# load data
data = pd.read_csv('otto/train.csv')
dataset = data.values
# split data into X and y
X = dataset[:, 0:94]
y = dataset[:, 94]
# encode string class values as integers
label_encoded_y = LabelEncoder().fit_transform(y)

############### enable gpu speedup ###############################
params = {'tree_method': 'gpu_hist', 'predictor': 'gpu_predictor'}
model = xgb.XGBClassifier(**params)
##################################################################
learning_rate = [0.0001, 0.001, 0.01, 0.1, 0.2, 0.3]
param_dict = dict(learning_rate=learning_rate)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(
    model, param_grid=param_dict, cv=kfold, scoring='neg_log_loss', n_jobs=-1)
grid_search.fit(X, label_encoded_y)
print('best param: ', grid_search.best_params_)
print('best score: ', grid_search.best_score_)

means = grid_search.cv_results_['mean_test_score']
stds = grid_search.cv_results_['std_test_score']
params = grid_search.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
    print("%f (%f) with: %r" % (mean, stdev, param))

best_model = grid_search.best_estimator_
with open('bst_xgb.pkl', 'wb') as f:
    pickle.dump(best_model, f)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值