from sklearn.ensemble import GradientBoostingRegressor
GradientBoostingRegressor(loss='ls', learning_rate=0.1, n_estimators=100, subsample=1.0,
criterion='friedman_mse', min_samples_split=2, min_samples_leaf=1,
min_weight_fraction_leaf=0.0, max_depth=3, min_impurity_decrease=0.0,
min_impurity_split=None, init=None, random_state=None, max_features=None,
alpha=0.9, verbose=0, max_leaf_nodes=None, warm_start=False, presort='auto',
validation_fraction=0.1, n_iter_no_change=None, tol=0.0001)'''
1.loss: 损失函数,‘ls’:此时损失函数为平方损失函数。
- ‘lad’:此时使用指数绝对值损失函数。
- ‘quantile’:分位数回归(分位数指的是百分之几),采用绝对值损失。
- ‘huber’:此时损失函数为上述两者的综合,即误差较小时,采用平方损失,在误差较大时,采用绝对值损失。
2.learning_rate:学习率
3.n_ estimators: 基学习器的个数,这里是树的颗数
4.subsample: 取值在(0, 1)之间,取原始训练集中的一个子集用于训练基础决策树
5.criterion: 'friedman_mse'改进型的均方误差;'mse'标准的均方误差; 'mae'平均绝对误差。
6.min_samples_split:一个整数,指定了每个基础决策树模型分裂所需最小样本数。
7.min_samples_leaf:一个整数,指定了每个基础决策树模型叶节点所包含的最小样本数。
8.min_weight_fraction_leaf:一个浮点数。叶节点的最小加权权重。当不提供sample_weight时,样本的权重是相等的。
9.max_depth:一个整数或者None,指定每一个基础决策树模型的最大深度。如果max_leaf_noeds不是None,则忽略此参数。
10.max_features:一个整数,浮点数或者None。代表节点分裂是参与判断的最大特征数。整数为个数,浮点数为所占比重。
11.max_leaf_nodes:为整数或者None,指定了每个基础决策树模型的最大叶节点数量。
12.min_impurity_split:一个浮点数,指定在树生长的过程中,节点分裂的阈值,默认为1e-7。
13.init:一个基础分类器对象或者None
14.alpha:一个浮点数,只有当loss=‘huber’或者loss=‘quantile’时才有效。
15.verbose:如果为0则不输出日志,如果为1,则每隔一段时间输出日志
16.warm_start:热启动,当你训练GBM到一定程度停止时,如果你想在这个基础上接着训练,就需要用到该参数减少重复训练;
属性
1.feature_importance_:一个数组,给出了每个特征的重要性(值越高重要性越大)。
2.oob_improvement_:一个数组,给出了每增加一棵基础决策树,在包外估计(即测试集)的损失函数的减少值。
3.train_score_:一个数组,给出每增加一棵基础决策树,在训练集上的损失函数的值。
4.loss:具体损失函数对象。
5.init:初始预测使用的分类器。
6.estimators_:一个数组,给出了每个基础决策树。
方法
1.apply(X) Apply trees in the ensemble to X, return leaf indices.
2.fit(X,y):训练模型。
3.get_params([deep]) Get parameters for this estimator.
4.predict(X):用模型进行预测,返回预测值。
5.score(X,y):返回在(X,y)上预测的准确率。
6.set_params(**params) Set the parameters of this estimator.
7.staged_predict(X):返回一个数组,数组元素依次是每一轮迭代结束时尚未完成的集成分类器的预测值。
'''
XGBoost 回归
from xgboost import XGBRegressor
XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True, objective='reg:linear',
booster='gbtree', n_jobs=1, nthread=None, gamma=0, min_child_weight=1, max_delta_step=0,
subsample=1, colsample_bytree=1, colsample_bylevel=1, reg_alpha=0, reg_lambda=1,
scale_pos_weight=1, base_score=0.5, random_state=0, seed=None, missing=None,**kwargs)'''
属性
1.feature_importances_ 给出每个特征的重要性。
用法
1.apply(X[, ntree_limit]) Return the predicted leaf every tree for
each sample.
2.evals_result() Return the evaluation results.
3.fit(X[, y]) Fit a gradient boosting classifier
4.get_booster() Get the underlying xgboost Booster of this model.
5.get_params([deep]) Get parameters.
6.get_xgb_params() Get xgboost type parameters.
7.predict(X) Predict with data.
8.score(X, y[, sample_weight]) Returns the mean accuracy on the given
test data and labels.
9.set_params(**params) Set the parameters of this estimator.
'''