xgboost例子

xiaoxiao2025-07-06  6

import numpy as np import xgboost as xgb

data = np.random.rand(5,10) # 5 entities, each contains 10 features label = np.random.randint(2, size=5) # binary target dtrain = xgb.DMatrix(data, label=label)

params = {     'booster': 'gbtree',     'objective': 'multi:softmax',  # 多分类的问题     'num_class': 10,               # 类别数,与 multisoftmax 并用     'gamma': 0.1,                  # 用于控制是否后剪枝的参数,越大越保守,一般0.1、0.2这样子。     'max_depth': 12,               # 构建树的深度,越大越容易过拟合     'lambda': 2,                   # 控制模型复杂度的权重值的L2正则化项参数,参数越大,模型越不容易过拟合。     'subsample': 0.7,              # 随机采样训练样本     'colsample_bytree': 0.7,       # 生成树时进行的列采样     'min_child_weight': 3,     'silent': 1,                   # 设置成1则没有运行信息输出,最好是设置为0.     'eta': 0.007,                  # 如同学习率     'seed': 1000,     'nthread': 4,                  # cpu 线程数 }

num_round = 10

bst = xgb.train( params, dtrain, num_round) # make prediction

# X_test类型可以是二维List,也可以是numpy的数组 dtest = DMatrix(X_test)

preds = bst.predict(dtest)

转自:xgboost 例子 + get_started

转载请注明原文地址: https://www.6miu.com/read-5032657.html

最新回复(0)