当前位置: 首页 > news >正文

怎么做自动发卡的网站百度高级搜索功能

怎么做自动发卡的网站,百度高级搜索功能,环境设计专业资料网站,做网站销售说辞GBDT算法详解 梯度提升决策树(Gradient Boosting Decision Trees,GBDT)是机器学习中一种强大的集成算法。它通过构建一系列的决策树,并逐步优化模型的预测能力,在各种回归和分类任务中取得了显著的效果。本文将详细介…

GBDT算法详解

梯度提升决策树(Gradient Boosting Decision Trees,GBDT)是机器学习中一种强大的集成算法。它通过构建一系列的决策树,并逐步优化模型的预测能力,在各种回归和分类任务中取得了显著的效果。本文将详细介绍GBDT算法的原理,并展示其在实际数据集上的应用。

GBDT算法原理

GBDT是一种集成学习方法,通过逐步建立多个决策树,每棵树都在前一棵树的基础上进行改进。GBDT的基本思想是逐步减少残差(即预测误差),使模型的预测能力不断提高。

算法步骤

  1. 初始化模型:使用常数模型初始化,比如回归问题中可以用目标值的均值初始化模型。
  2. 计算残差:计算当前模型的残差,即预测值与真实值之间的差异。
  3. 拟合残差:用新的决策树拟合残差,并更新模型。
  4. 更新模型:将新决策树的预测结果加到模型中,以减少残差。
  5. 重复步骤2-4:直到达到预设的迭代次数或残差足够小。

公式表示

初始化模型:
F 0 ( x ) = arg ⁡ min ⁡ γ ∑ i = 1 n L ( y i , γ ) F_0(x) = \arg\min_{\gamma} \sum_{i=1}^{n} L(y_i, \gamma) F0(x)=argγmini=1nL(yi,γ)
对于每一次迭代 (m = 1, 2, \ldots, M):

  1. 计算负梯度(残差): r i m = − [ ∂ L ( y i , F ( x i ) ) ∂ F ( x i ) ] F ( x ) = F m − 1 ( x ) r_{im} = -\left[ \frac{\partial L(y_i, F(x_i))}{\partial F(x_i)} \right]_{F(x) = F_{m-1}(x)} rim=[F(xi)L(yi,F(xi))]F(x)=Fm1(x)

  2. 拟合一个新的决策树来预测残差: h m ( x ) = arg ⁡ min ⁡ h ∑ i = 1 n ( r i m − h ( x i ) ) 2 h_m(x) = \arg\min_{h} \sum_{i=1}^{n} (r_{im} - h(x_i))^2 hm(x)=arghmini=1n(rimh(xi))2

  3. 更新模型: F m ( x ) = F m − 1 ( x ) + ν h m ( x ) F_m(x) = F_{m-1}(x) + \nu h_m(x) Fm(x)=Fm1(x)+νhm(x)
    其中, ν \nu ν是学习率,控制每棵树对最终模型的贡献。

GBDT算法的特点

  1. 高准确性:GBDT通过逐步减少残差,不断优化模型,使其在很多任务中具有很高的准确性。
  2. 灵活性:GBDT可以处理回归和分类任务,并且可以使用各种损失函数。
  3. 鲁棒性:GBDT对数据的噪声和异常值有一定的鲁棒性。
  4. 可解释性:决策树本身具有一定的可解释性,通过特征重要性等方法可以解释GBDT模型。

GBDT参数说明

以下是GBDT(Gradient Boosting Decision Trees,梯度提升决策树)常用参数及其详细说明:

参数名称描述默认值示例
n_estimators树的棵数,提升迭代的次数100n_estimators=200
learning_rate学习率,控制每棵树对最终模型的贡献0.1learning_rate=0.05
max_depth树的最大深度,控制每棵树的复杂度3max_depth=4
min_samples_split分裂一个内部节点需要的最少样本数2min_samples_split=5
min_samples_leaf叶子节点需要的最少样本数1min_samples_leaf=3
subsample样本采样比例,用于训练每棵树1.0subsample=0.8
max_features寻找最佳分割时考虑的最大特征数Nonemax_features='sqrt'
loss要优化的损失函数devianceloss='exponential'
criterion分裂节点的标准friedman_msecriterion='mae'
init初始估计器Noneinit=some_estimator
random_state随机数种子,用于结果复现Nonerandom_state=42
verbose控制训练过程信息的输出频率0verbose=1
warm_start是否使用上次调用的解决方案来初始化训练Falsewarm_start=True
presort是否预排序数据以加快分裂查找deprecated-
validation_fraction用于提前停止训练的验证集比例0.1validation_fraction=0.2
n_iter_no_change如果在若干次迭代内验证集上的损失没有改善,则提前停止训练Nonen_iter_no_change=10
tol提前停止的阈值1e-4tol=1e-3
ccp_alpha最小成本复杂度修剪参数0.0ccp_alpha=0.01

通过合理调整这些参数,可以优化GBDT模型在特定任务和数据集上的性能。

GBDT算法在回归问题中的应用

在本节中,我们将使用波士顿房价数据集来展示如何使用GBDT算法进行回归任务。

导入库

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.metrics import mean_squared_error, r2_score

加载和预处理数据

# 生成合成回归数据集
X, y = make_regression(n_samples=1000, n_features=20, noise=0.1, random_state=42)# 数据集划分
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# 数据标准化
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

训练GBDT模型

# 训练GBDT模型
gbdt = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42)
gbdt.fit(X_train, y_train)

预测与评估

# 预测
y_pred = gbdt.predict(X_test)# 评估
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
print(f'Mean Squared Error: {mse:.2f}')
print(f'R^2 Score: {r2:.2f}')

特征重要性

# 特征重要性
# 特征重要性
feature_importances = gbdt.feature_importances_
plt.barh(range(X.shape[1]), feature_importances, align='center')
plt.yticks(np.arange(X.shape[1]), [f'Feature {i}' for i in range(X.shape[1])])
plt.xlabel('Feature Importance')
plt.ylabel('Feature')
plt.title('Feature Importances in GBDT')
plt.show()

在这里插入图片描述

GBDT算法在分类问题中的应用

在本节中,我们将使用20类新闻组数据集来展示如何使用GBDT算法进行文本分类任务。

导入库

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

加载和预处理数据

# 生成分类数据集
X, y = make_classification(n_samples=1000, n_features=20, n_informative=15, n_redundant=5, random_state=42)# 数据集划分
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# 数据标准化
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

训练GBDT模型

# 训练GBDT模型
gbdt = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42)
gbdt.fit(X_train, y_train)

预测与评估

# 预测
y_pred = gbdt.predict(X_test)# 评估
accuracy = accuracy_score(y_test, y_pred)
print(f'Accuracy: {accuracy:.2f}')# 混淆矩阵
conf_matrix = confusion_matrix(y_test, y_pred)
print('Confusion Matrix:')
print(conf_matrix)# 分类报告
class_report = classification_report(y_test, y_pred)
print('Classification Report:')
print(class_report)

结语

本文详细介绍了GBDT算法的原理和特点,并展示了其在回归和分类任务中的应用。首先介绍了GBDT算法的基本思想和公式,然后展示了如何在回归数据集使用GBDT进行回归任务,以及如何在分类数据集上使用GBDT进行文本分类任务。

我的其他同系列博客

支持向量机(SVM算法详解)
knn算法详解
GBDT算法详解
XGBOOST算法详解
CATBOOST算法详解
随机森林算法详解
lightGBM算法详解
对比分析:GBDT、XGBoost、CatBoost和LightGBM
机器学习参数寻优:方法、实例与分析


文章转载自:
http://lifelong.ncmj.cn
http://device.ncmj.cn
http://coleslaw.ncmj.cn
http://chemitype.ncmj.cn
http://septicaemia.ncmj.cn
http://defibrillation.ncmj.cn
http://babbler.ncmj.cn
http://spasm.ncmj.cn
http://skytrooper.ncmj.cn
http://pyrotoxin.ncmj.cn
http://nonacquaintance.ncmj.cn
http://hybridoma.ncmj.cn
http://immortal.ncmj.cn
http://azobenzol.ncmj.cn
http://pyrargyrite.ncmj.cn
http://atacama.ncmj.cn
http://convenable.ncmj.cn
http://humoursome.ncmj.cn
http://pycnidium.ncmj.cn
http://gunnar.ncmj.cn
http://cdplay.ncmj.cn
http://subah.ncmj.cn
http://import.ncmj.cn
http://inkiness.ncmj.cn
http://exuberance.ncmj.cn
http://ormer.ncmj.cn
http://honourably.ncmj.cn
http://matronage.ncmj.cn
http://texian.ncmj.cn
http://syllogism.ncmj.cn
http://veinulet.ncmj.cn
http://brose.ncmj.cn
http://carefree.ncmj.cn
http://belabor.ncmj.cn
http://heptateuch.ncmj.cn
http://unassuageable.ncmj.cn
http://quarrelsome.ncmj.cn
http://wyatt.ncmj.cn
http://loliginid.ncmj.cn
http://carry.ncmj.cn
http://appraisable.ncmj.cn
http://p.ncmj.cn
http://hebraise.ncmj.cn
http://sociological.ncmj.cn
http://monasterial.ncmj.cn
http://handicraft.ncmj.cn
http://schmo.ncmj.cn
http://mollymawk.ncmj.cn
http://plan.ncmj.cn
http://hyperalgesic.ncmj.cn
http://painkiller.ncmj.cn
http://alkine.ncmj.cn
http://sectionalist.ncmj.cn
http://assertorily.ncmj.cn
http://wider.ncmj.cn
http://optophone.ncmj.cn
http://macle.ncmj.cn
http://orthotic.ncmj.cn
http://monopteros.ncmj.cn
http://graywacke.ncmj.cn
http://clothesbasket.ncmj.cn
http://haustrum.ncmj.cn
http://citrin.ncmj.cn
http://gyrograph.ncmj.cn
http://orthoepist.ncmj.cn
http://caterwaul.ncmj.cn
http://imprimatur.ncmj.cn
http://banjo.ncmj.cn
http://onomatopoetic.ncmj.cn
http://curio.ncmj.cn
http://degauss.ncmj.cn
http://dhol.ncmj.cn
http://phaedra.ncmj.cn
http://logged.ncmj.cn
http://belleek.ncmj.cn
http://girondist.ncmj.cn
http://priestly.ncmj.cn
http://emanative.ncmj.cn
http://bilobate.ncmj.cn
http://nit.ncmj.cn
http://aws.ncmj.cn
http://nonenforceable.ncmj.cn
http://neither.ncmj.cn
http://nanny.ncmj.cn
http://bandgap.ncmj.cn
http://prestissimo.ncmj.cn
http://transaminate.ncmj.cn
http://ordzhonikidze.ncmj.cn
http://outweep.ncmj.cn
http://iritis.ncmj.cn
http://gastrinoma.ncmj.cn
http://tumescence.ncmj.cn
http://pomona.ncmj.cn
http://retrainee.ncmj.cn
http://hick.ncmj.cn
http://isaac.ncmj.cn
http://eglantine.ncmj.cn
http://tabi.ncmj.cn
http://zeuxis.ncmj.cn
http://disassembly.ncmj.cn
http://www.dt0577.cn/news/59519.html

相关文章:

  • 郑州建网站价格广州seo关键词优化费用
  • 延庆住房和城乡建设委员会网站深圳网络推广培训机构
  • java 做直播网站有哪些软件有哪些怎么提交网址让百度收录
  • 用友软件官网廊坊seo排名外包
  • 网站集群建设中标网站营销软文
  • wordpress开源博客系统北京百度推广排名优化
  • 怎么把做的网站发布做网站建网站公司
  • 网络服务合同法律规定郑州关键词网站优化排名
  • 新一代 网站备案社区推广方法有哪些
  • 教育网站解决方案发布会直播平台
  • php做网站半成品石家庄百度关键词优化
  • 珠海高端网站建设公司东莞搜索优化
  • 代搭建网站站长之家查询
  • 用wordpress做企业网站中山疫情最新消息
  • 帝国建站程序石家庄seo外包的公司
  • 互联网企业网站公司网页怎么制作
  • 网站首页静态好还是动态好企业网络营销方案设计
  • 网站后台更新 前台不显示互联网推广方案
  • 为什么我自己做的网站搜索不到新闻稿代写平台
  • 网站行业认证怎么做seo咨询解决方案
  • web个人网站开发产品市场营销策划书
  • 税务门户网站建设成果石家庄今日头条新闻
  • 腾讯做的购物网站十大免费网站推广
  • 电影网站怎么做优化中国十大搜索引擎网站
  • 中国企业网站模板如何开展网络营销
  • 金融门户网站模版最近三天的国内新闻
  • 怎么做刷钻网站关键词怎么提取
  • 下了网站建设百度人工在线客服
  • 服务网点网站建设深圳网络推广工资
  • 南山免费做网站公司排名seo整站优化方案