GBDT分类实战完全总结(一)

第一部分:参数说明
(一)、简述
sklearn自带的ensemble模块中集成了GradientBoostingClassifier的类,参数包括:
class  sklearn.ensemble. GradientBoostingClassifier ( loss=’deviance’ 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 verbose=0 max_leaf_nodes=None warm_start=False presort=’auto’ ) 源代码见 [source]
(二)、参数含义及可取的值
●表示可选参数,★ 表示默认参数
1、 loss  : {‘deviance’, ‘exponential’}, optional (default=’deviance’)---------损失函数
● exponential:模型等同AdaBoost
★ deviance:和Logistic Regression的损失函数一致
2、 learning_rate  : float, optional (default=0.1)-------- 学习率(缩减)
注: 即每个弱学习器的权重缩减系数ν,也称作步长,ν的取值范围为0<ν≤1。
3、 n_estimators  : int (default=100)-------- 子模型的数量
● int:个数
★ 100:默认值
注:大量提升时性能更好。
4、 max_depth  : integer, optional (default=3)--------- 最大深度,如果max_leaf_nodes参数指定,则忽略
● int:深度
★ 3:默认值
5、 criterion  : string, optional (default=”friedman_mse”)--------如何划分特征
注:Supported criteria are “friedman_mse” for the mean squared error with improvement score by Friedman, “mse” for mean squared error, and “mae” for the mean absolute error.
6、 min_samples_split  : int, float, optional (default=2)------- 分裂所需的最小样本数
● int:样本数
★ 2:默认值
注:如果为int,则将min_samples_split作为最小值。
如果为float,则min_samples_split为百分比,ceil(min_samples_split * n_samples)为每个分割的最小采样数。
7、 min_samples_leaf  : int, float, optional (default=1)------- 叶节点最小样本数
● int:样本数
★ 1:默认值
注:如果为int,则将min_samples_leaf视为最小值。
如果为float,则min_samples_leaf是百分比,ceil(min_samples_leaf * n_samples)是每个节点的最小采样数。
8、 min_weight_fraction_leaf  : float, optional (default=0.)------- 叶节点最小样本权重总值
● float:权重总值
★ 0:默认值
注:需要在叶节点处的所有输入样本权重总和的最小加权分数。 没有提供sample_weight时,样本具有相同的权重。
9、 subsample  : float, optional (default=1.0)------ 子采样率
● float:采样率
★ 1.0:默认值
注:如果小于1.0,则会导致随机梯度增强(Stochastic Gradient Boosting)。 子样本与参数n_estimators交互。 选择子样本<1.0会导致方差减少和偏差增加。 推荐在[0.5, 0.8]之间,默认是1.0,即不使用子采样。
10、 max_features  : int, float, string or None, optional (default=None)--- 节点分裂时参与判断的最大特征数
● int:个数
● float:占所有特征的百分比
● auto:所有特征数的开方
● sqrt:所有特征数的开方
● log2:所有特征数的log2值
★ None:等于所有特征数
注:选择max_features <n_features会导致方差减少和偏差增加。
11、 max_leaf_nodes  : int or None, optional (default=None)------ 最大叶节点数
● int:个数
★ None:不限制叶节点数
12、 min_impurity_split  : float----------停止划分的阈值
注: Deprecated since version 0.19:  min_impurity_split  has been deprecated in favor of min_impurity_decrease  in 0.19 and will be removed in 0.21. Use min_impurity_decrease  instead.
13、 min_impurity_decrease  : float, optional (default=0.)----------停止划分的阈值
注:如果此分割导致大于或等于该值的纯度减少,则节点将被分割。
纯度方程: N_t / N * (impurity - N_t_R / N_t * right_impurity - N_t_L / N_t * left_impurity)
14、 init  : BaseEstimator, None, optional (default=None)-------- 初始子模型
注:用于计算初始预测的估计器对象。 init必须提供拟合和预测。 如果没有,它使用loss.init_estimator。
15、 verbose  : int, default: 0------- 日志冗长度
● int:冗长度
★ 0:不输出训练过程
● 1:偶尔输出
● >1:对每个子模型都输出
16、 warm_start  : bool, default: False-------- 是否热启动,如果是,则下一次训练是以追加树的形式进行
● bool:热启动
★ False:默认值
17、 random_state  : int, RandomState instance or None, optional (default=None)--- 随机器对象
注:如果是int,random_state是随机数发生器使用的种子; 如果RandomState实例,random_state是随机数生成器; 如果为None,则随机数生成器是np.random使用的RandomState实例。
18、 presort  : bool or ‘auto’, optional (default=’auto’)--------- 是否预排序,预排序可以加速查找最佳分裂点,对于稀疏数据不管用
● Bool
★ auto:非稀疏数据则预排序,若稀疏数据则不预排序
注: 默认情况下,自动模式将对密集数据使用预排序,并且默认对稀疏数据进行正常排序。 在稀疏数据上将presort设置为true会引发错误。
(三)、属性Attributes说明
1、 feature_importances_  : array, shape = [n_features]------------输出特征的重要性,越大越重要
2、 oob_improvement_  : array, shape = [n_estimators]---------损失函数的提升
3、 train_score_  : array, shape = [n_estimators]-------
4、 loss_  : LossFunction
5、 init  : BaseEstimator------ 即我们的初始化的时候的弱学习器,拟合对应原理篇里面的f0(x),如果不输入,则用训练集样本来做样本集的初始化分类回归预测。否则用init参数提供的学习器做初始化分类回归预测。一般用在我们对数据有先验知识,或者之前做过一些拟合的时候,如果没有的话就不用管这个参数了。
6、 estimators_  : ndarray of DecisionTreeRegressor, shape = [n_estimators,  loss_.K ]
(四)、Methods
1、apply(X)-------将集合中的树应用于X,返回叶索引。
注:Parameters: X : array-like or sparse matrix, shape = [n_samples, n_features]
Returns: X_leaves : array_like, shape = [n_samples, n_estimators, n_classes]
2、decision_function(X)------计算决策树
Parameters:
X : array-like or sparse matrix, shape = [n_samples, n_features]
Returns:
score : array, shape = [n_samples, n_classes] or [n_samples]
3、feature_importances_-------------返回特征重要性
4、fit(X, y, sample_weight=None, monitor=None)----拟合the gradient boosting model.
5、get_params(deep=True)
6、n_features
7、predict(X)------预测函数
8、predict_log_proba(X)--------预测概率的log值
9、predict_proba(X)-----------预测概率
10、score(X, y, sample_weight=None)-----返回平均精度
11、set_params(**params)
12、staged_decision_function(X)
13、staged_predict(X)
15、staged_predict_proba(X)
实战部分见下一博文

猜你喜欢

转载自blog.csdn.net/xiaoliuhexiaolu/article/details/80582247