GBDT+LR算法解析及Python实现 (2)

 

GBDT+LR算法解析及Python实现

 

GBDT+LR算法解析及Python实现

5. GBDT + LR 代码分析

在网上找到了两个版本的GBDT+LR的代码实现,通过阅读分析,认为里面有一些细节还是值得好好学习一番的,所以接下来这一小节会针对代码实现部分做一些总结。

首先,目前我所了解到的GBDT的实现方式有两种:一是利用Scikit-learn中的ensemble.GradientBoostingClassifier ,二是利用lgb里的params={ 'boosting_type': 'gbdt' }参数。接下里分别对这两种实现方式进行分析。

5.1 Scikit-learn的实现:

from sklearn.preprocessing import OneHotEncoder from sklearn.ensemble import GradientBoostingClassifier gbm1 = GradientBoostingClassifier(n_estimators=50, random_state=10, subsample=0.6, max_depth=7, min_samples_split=900) gbm1.fit(X_train, Y_train) train_new_feature = gbm1.apply(X_train) train_new_feature = train_new_feature.reshape(-1, 50) enc = OneHotEncoder() enc.fit(train_new_feature) # # 每一个属性的最大取值数目 # print('每一个特征的最大取值数目:', enc.n_values_) # print('所有特征的取值数目总和:', enc.n_values_.sum()) train_new_feature2 = np.array(enc.transform(train_new_feature).toarray())

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpydwd.html