关于人工智能:LCE一个结合了随机森林和XGBoost优势的新的集成方法

4次阅读

共计 5434 个字符,预计需要花费 14 分钟才能阅读完成。

随机森林 [Breiman, 2001] 和 XGBoost [Chen and Guestrin, 2016] 已成为解决分类和回归的许多挑战的最佳机器学习办法。Local Cascade Ensemble (LCE) [Fauvel et al., 2022] 是一种新的机器学习办法,它联合了它们的劣势并采纳互补的多样化办法来取得更好的泛化预测器。因而,LCE 进一步加强了随机森林和 XGBoost 的预测性能。

本文介绍了 LCE 和相应的 Python 包以及一些代码示例。LCE 包与 scikit-learn 兼容并通过了 check_estimator 测试,所以它能够 十分不便的集成到 scikit-learn 管道中。

LCE 简介

集成办法的构建波及联合绝对精确和多样化的个体预测器。有两种互补的办法能够生成不同的预测变量:(i)通过扭转训练数据分布和(ii)通过学习训练数据的不同局部。

LCE 采纳了这两种多样化的办法。(i) LCE 联合了两种家喻户晓的办法,这些办法能够批改原始训练数据的散布,并具备对偏差 - 方差衡量的互补效应:bagging [Breiman, 1996](方差缩小)和 boosting [Schapire, 1990](缩小偏差)。(ii) LCE 学习训练数据的不同局部,这样能够捕捉基于分而治之策略(决策树)无奈发现的全局关系。在具体介绍 LCE 如何联合这些办法之前,咱们先介绍它们背地的要害概念,这些概念将用于解释 LCE。

偏差 - 方差衡量定义了学习算法在训练集之外泛化的能力。高偏差意味着学习算法无奈捕获训练集的底层构造(欠拟合)。高方差意味着算法对训练集的学习过于严密(过拟合)。所有训练的指标都是最小化偏差和方差。

Bagging 对方差缩小有次要作用:它是一种生成多个版本的预测器(bootstrap replicates)并应用它们来取得聚合预测器的办法。目前 bagging 的最先进的办法是随机森林。

Boosting 对缩小偏差有次要作用:它是一种迭代学习弱预测器并将它们相加以创立最终强预测器的办法。增加弱学习器后,从新调整数据权重,让将来的弱学习器更多地关注先前弱学习器预测谬误的示例。目前应用晋升的最先进的办法是 XGBoost。图 1 阐明了 bagging 和 boosting 办法之间的区别。

图 1. plant diseases 数据集上的 Bagging 与 Boosting。n – 预计器的数量。

新集成办法 LCE 联合了 boosting-bagging 办法来解决机器学习模型面临的偏差 - 方差衡量;此外,它采纳分而治之的办法来个性化训练数据不同局部的预测误差。LCE 如图 2 所示。

图 2. plant diseases 数据集上的 Local Cascade Ensemble,参考图 1,蓝色为 Bagging,红色为 Boosting。n — 树的数量,XGB — XGBoost。

具体来说,LCE 基于级联泛化:它按程序应用一组预测器,并在每个阶段向输出数据集增加新属性。新属性来自预测器(例如,分类器的类概率)给出的输入,称为根底学习器。LCE 采纳分治策略 (决策树) 在部分利用级联泛化,并通过应用基于晋升的预测器作为根底学习器来缩小决策树的偏差。LCE 采纳以后性能最好的最先进的 boosting 算法作为根底学习器(XGBoost,例如图 2 中的 XGB¹⁰、XGB¹¹)。在生成树的过程中,将每个决策节点处的基学习器的输入作为新属性增加到数据集(例如,图 2 中的 XGB¹⁰(D¹))来沿树向下流传晋升。预测输入表明根底学习器正确预测样本的能力。在下一个树级别,增加到数据集的输入被根底学习器用作加权计划,这样能够更多的关注先前谬误预测的样本。最初通过应用 bagging 来加重由晋升树产生的过拟合。Bagging 通过从随机抽样中创立多个预测变量并替换原始数据集(例如,图 2 中的 D¹、D²)以简略多数票聚合树来升高方差。LCE 在每个节点中存储由基学习器生成的模型。

对于缺失数据的解决。与 XGBoost 相似,LCE 排除了拆散的缺失值,并应用块流传。在节点拆散过程中,块流传将所有缺失数据的样本发送到谬误较少的决策节点一侧。

LCE 的超参数是基于树的学习中的经典超参数(例如,max_depth、max_features、n_estimators)。此外,LCE 在树的每个节点上学习一个特定的 XGBoost 模型,它只须要指定 XGBoost 超参数的范畴。而后,每个 XGBoost 模型的超参数由 Hyperopt [Bergstra et al., 2011] 主动设置,这是一种应用 Parzen 预计树算法的基于程序模型的优化。Hyperopt 从先前的抉择和基于树的优化算法中抉择下一个超参数。Parzen 预计树的最终后果个别与超参数设置的网格搜寻和随机搜寻性能相当并且大部分状况下会更好。

在 [Fauvel et al., 2022] 的公共 UCI 数据集 [Dua and Graff, 2017] 上其进行了评估。结果表明与最先进的分类器(包含随机森林和 XGBoost)相比,LCE 均匀取得了更好的预测性能。

Python 包和代码示例

LCE 要求 Python ≥ 3.7 并且间接应用 pip 装置

pip install lcensemble

conda 应用上面命令装置

conda install -c conda-forge lcensemble

LCE 包与 scikit-learn 兼容,它能够间接与 scikit-learn 管道和模型抉择工具进行交互。以下示例阐明了在公共数据集上应用 LCE 进行分类和回归工作。还显示了蕴含缺失值的数据集上的 LCE 示例。

Iris 数据集上的这个示例阐明了如何训练 LCE 模型并将其用作预测器。它还通过应用 cross_val_score 演示了 LCE 与 scikit-learn 模型抉择工具的兼容性。

from lce import LCEClassifier
from sklearn.datasets import load_iris
from sklearn.metrics import classification_report
from sklearn.model_selection import cross_val_score, train_test_split
# Load data and generate a train/test split
data = load_iris()
X_train, X_test, y_train, y_test = train_test_split(data.data, 
                                                    data.target, 
                                                    random_state=0)

# Train LCEClassifier with default parameters
clf = LCEClassifier(n_jobs=-1, random_state=123)
clf.fit(X_train, y_train)

# Make prediction and generate classification report
y_pred = clf.predict(X_test)
print(classification_report(y_test, y_pred))

print(cross_val_score(clf, data.data, data.target, cv=3))
[0.98 0.94 0.96]

这个例子阐明了 LCE 对缺失值的鲁棒性。应用每个变量 20% 的缺失值对 Iris 训练集进行了批改。

import numpy as np
from lce import LCEClassifier
from sklearn.datasets import load_iris
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
# Load data and generate a train/test split
data = load_iris()
X_train, X_test, y_train, y_test = train_test_split(data.data, 
                                                    data.target, 
                                                    random_state=0)

# Input 20% of missing values per variable in the train set
np.random.seed(0)
m = 0.2
for j in range(0, X_train.shape[1]):
    sub = np.random.choice(X_train.shape[0], int(X_train.shape[0]*m))
    X_train[sub, j] = np.nan

# Train LCEClassifier with default parameters
clf = LCEClassifier(n_jobs=-1, random_state=123)
clf.fit(X_train, y_train)

# Make prediction and generate classification report
y_pred = clf.predict(X_test)
print(classification_report(y_test, y_pred))

最初,这个例子展现了如何在回归工作中应用 LCE。

from lce import LCERegressor
from sklearn.datasets import load_diabetes
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
# Load data and generate a train/test split
data = load_diabetes()
X_train, X_test, y_train, y_test = train_test_split(data.data, 
                                                    data.target, 
                                                    random_state=0)

# Train LCERegressor with default parameters
reg = LCERegressor(n_jobs=-1, random_state=0)
reg.fit(X_train, y_train)

# Make prediction 
y_pred = reg.predict(X_test)
mse = mean_squared_error(y_test, reg.predict(X_test))
print("The mean squared error (MSE) on test set: {:.0f}".format(mse))

# The mean squared error (MSE) on test set: 3556

总结

本文介绍 LCE,是一种用于个别分类和回归工作的新集成办法,该办法的作者也间接提供了相干的以 Python 包可能够间接让咱们应用。

https://avoid.overfit.cn/post/c10cc8f023484c95bab2bff5dd37c74c

最初是本文的援用

J. Bergstra, R. Bardenet, Y. Bengio and B. Kégl. Algorithms for Hyper-Parameter Optimization. In Proceedings of the 24th International Conference on Neural Information Processing Systems, 2011.

L. Breiman. Bagging Predictors. Machine Learning, 24(2):123–140, 1996.

L. Breiman. Random Forests. Machine Learning, 45(1):5–32, 2001.

T. Chen and C. Guestrin. XGBoost: A Scalable Tree Boosting System. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 2016.

D. Dua and C. Graff. UCI Machine Learning Repository, 2017.

K. Fauvel, V. Masson, E. Fromont, P. Faverdin and A. Termier. Towards Sustainable Dairy Management — A Machine Learning Enhanced Method for Estrus Detection. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 2019.

K. Fauvel, E. Fromont, V. Masson, P. Faverdin and A. Termier. XEM: An Explainable-by-Design Ensemble Method for Multivariate Time Series Classification. Data Mining and Knowledge Discovery, 36(3):917–957, 2022.

R. Schapire. The Strength of Weak Learnability. Machine Learning, 5(2):197–227, 1990.

作者:Kevin Fauvel

正文完
 0