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

php网站建设详细教程互联网行业属于什么行业

php网站建设详细教程,互联网行业属于什么行业,wordpress怎么上传头像不显示,采集到wordpress编译工具#xff1a;PyCharm 文章目录 编译工具#xff1a;PyCharm 集成学习XGBoost(Extreme Gradient Boosting)极端梯度提升树1.最优模型的构建方法XGBoost目标函数案例1#xff1a;泰坦尼克号案例2#xff1a;对奥拓集团差评进行正确分类。数据准备#xff1a;1.第一种…编译工具PyCharm 文章目录 编译工具PyCharm 集成学习XGBoost(Extreme Gradient Boosting)极端梯度提升树1.最优模型的构建方法XGBoost目标函数案例1泰坦尼克号案例2对奥拓集团差评进行正确分类。数据准备1.第一种基础的训练方式(不全作对比)2.第二种优化后的训练方式2.1数据处理部分2.2模型训练及调优 集成学习 解决欠拟合问题弱弱组合变强boosting 解决过拟合问题互相遏制变壮Bagging 集成学习(Ensemble learning)通过构建并结合多个学习器来完成学习任务。 同质 同质(homogeneous)集成集成中只包含同种类型的“个体学习器”相应的学习算法称为“基学习算法”(base learning algorithm) 个体学习器亦称“基学习器”(base learner) 异质(heterogeneous)集成个体学习器由不同的学习算法生成不存在“基学习算法” Bagging方法(并行) boosting方法(串行)基本思想基分类器层层叠加每一层在训练的时候对前一层基分类器分错的样本给予更高的权重。 XGBoost(Extreme Gradient Boosting)极端梯度提升树 1.最优模型的构建方法 构建最优模型的一般方法最小化训练数据的损失函数。 1.1经验风险最小化训练得到的模型复杂度哈皮但是当训练数据集较小的时候模型容易出现问题。 为进度模型复杂度采用2.1结构风险最小化它对训练数据以及未知数据都有较好的预测。 J(f)是模型的复杂度 应用 决策树的生成经验风险最小化 剪枝结构风险最小化 XGBoost的决策树生成结构风险最小化 XGBoost目标函数 正则化损失函数 CART树 树的复杂度 目标函数 目标函数推导过程 分裂节点计算 分开前-分开后结果0可以进行分裂0不进行 γ减去一个加入新叶子节点引入的复杂度代价。 案例1泰坦尼克号 数据集https://hbiostat.org/data/repo/titanic.txt # xgboost import pandas as pd import numpy as np from sklearn.model_selection import train_test_split # 进行数据集划分 from sklearn.feature_extraction import DictVectorizer import matplotlib.pyplot as plt from xgboost import XGBClassifier# 读取数据 # titan pd.read_csv(https://hbiostat.org/data/repo/titanic.txt) titan pd.read_csv(./data/titanic.csv) # print(titan.describe())# 获取样本和目标值 # 这里取pclass社会等级、age年龄、sex性别作为特征值 # 取survived存活为目标值 x titan[[pclass,age,sex]] y titan[survived]# 缺失值处理:对age为空的用平均值替换 x[age].fillna(valuetitan[age].mean(),inplaceTrue) # print(x.head())# 数据集划分 x_train,x_test,y_train,y_test train_test_split(x,y,random_state22,test_size0.2) # 特征抽取(字典特征提取) x_train x_train.to_dict(orientrecords) x_test x_test.to_dict(orientrecords) tranfer DictVectorizer() x_train tranfer.fit_transform(x_train) x_test tranfer.fit_transform(x_test)# xgboost 初步模型训练 # 实例化 xg XGBClassifier() # 训练 xg.fit(x_train,y_train) # 初步模型评估 print(xg初步模型训练评估: ,xg.score(x_test, y_test))# xgboost 调优模型训练 depth_range range(5) score [] for i in depth_range:xgXGBClassifier(eta1,gamma0,max_depthi)xg.fit(x_train,y_train)s xg.score(x_test,y_test)print(第,i1,次训练评估: ,s)score.append(s) # 对调优结果可视化 # plt.plot(depth_range,score) # plt.show()案例2对奥拓集团差评进行正确分类。 数据准备 数据集https://download.csdn.net/download/weixin_42320758/15728128?utm_sourcebbsseo 使用pycharm下载包的时候容易下载不成功建议使用清华大学提供的网站进行下载 -i https://pypi.tuna.tsinghua.edu.cn/simple 包名称 在命令行进行下载也可以使用 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 1.第一种基础的训练方式(不全作对比) 数据分割使用train_test_split 模型训练选择RF进行模型训练 import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # 欠采样方法从大量数据中抽取数据 from imblearn.under_sampling import RandomUnderSampler # 将标签转化为数字 from sklearn.preprocessing import LabelEncoder # 数据分割 from sklearn.model_selection import train_test_split # RF模型训练 from sklearn.ensemble import RandomForestClassifier # log_loss模型评估 from sklearn.metrics import log_loss # one-hot处理数据 from sklearn.preprocessing import OneHotEncoder# 获取数据 data pd.read_csv(./data/otto_train.csv) # 数据标签可视化查看数据的分布情况 sns.countplot(data.target) plt.show()x data.drop([id,target], axis1) y data[target] # 数据已结果脱敏处理(保护一些隐私等信息的安全) # 截取部分数据进行训练防止数据量过大 # 使用欠采样的方法获取数据注意不能直接按照前n行的方式进行截取 rus RandomUnderSampler(random_state0) x_resampled,y_resampled rus.fit_resample(x,y) sns.countplot(y_resampled) plt.show()# 将标签转数字 le LabelEncoder() y_resampled le.fit_transform(y_resampled) print(y_resampled)# 数据分割 x_train,x_test,y_train,y_test train_test_split(x_resampled,y_resampled,test_size0.2) print(x_train.shape,y_train.shape) print(x_test.shape,y_test.shape)# 模型训练1 # 基于RF模型训练 rf RandomForestClassifier(oob_scoreTrue) rf.fit(x_train,y_train) y_pre rf.predict(x_test) print(基于RF模型训练的评估结果score:,rf.score(x_test, y_test)) # log_loss模型评估 # log_loss(y_test,y_pre,eps1e-15,normalizeTrue) # 这样子写会报错,log_loss中要求输出用one-hot表示 # one-hot处理 one_hotOneHotEncoder(sparseFalse) y_test1one_hot.fit_transform(y_test.reshape(-1,1)) y_pre1 one_hot.fit_transform(y_pre.reshape(-1,1)) print(log_loss评估结果:,log_loss(y_test1, y_pre1, eps1e-15, normalizeTrue)) 原始数据标签可视化,查看数据的分布情况 数据量过大用欠采样的方法抽取部分数据后标签可视化 输出结果 2.第二种优化后的训练方式 数据分割处理StratifiedShuffleSplit 2.1数据处理部分 import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # 欠采样方法从大量数据中抽取数据 from imblearn.under_sampling import RandomUnderSampler # 将标签转化为数字 from sklearn.preprocessing import LabelEncoder # 数据分割 from sklearn.model_selection import StratifiedShuffleSplit # 数据标准化 from sklearn.preprocessing import StandardScaler # 数据pca降维 from sklearn.decomposition import PCA# 获取数据 data pd.read_csv(./data/otto_train.csv) # 数据标签可视化查看数据的分布情况 # sns.countplot(data.target) # plt.show()x data.drop([id,target], axis1) y data[target] # 数据已结果脱敏处理(保护一些隐私等信息的安全) # 截取部分数据进行训练防止数据量过大 # 使用欠采样的方法获取数据注意不能直接按照前n行的方式进行截取 rus RandomUnderSampler(random_state0) x_resampled,y_resampled rus.fit_resample(x,y) # sns.countplot(y_resampled) # plt.show()# 将标签转数字 le LabelEncoder() y_resampled le.fit_transform(y_resampled) print(标签转为数值后: ,y_resampled)# 数据分割 x_train [] x_val [] y_train [] y_val[] sss StratifiedShuffleSplit(n_splits1,test_size0.2,random_state0) for train_index,test_index in sss.split(x_resampled.values,y_resampled):# print(len(train_index))# print(len(test_index))x_train x_resampled.values[train_index] # 训练集的数据x_val x_resampled.values[test_index] # 测试集的数据y_train y_resampled[train_index] # 训练集的标签y_val y_resampled[test_index] # 测试集的标签print(训练集和测试集的大小:,x_train.shape,x_val.shape) # 分割后的数据可视化 # sns.countplot(y_val) # plt.show()# 数据标准化 scaler StandardScaler() scaler.fit(x_train) x_train_scaled scaler.transform(x_train) x_val_scaled scaler.transform(x_val)# 数据pca降维 pca PCA(n_components0.9) x_train_pca pca.fit_transform(x_train_scaled) x_val_pca pca.transform(x_val_scaled) print(pca降维后: ,x_train_pca.shape,x_val_pca.shape) # 可视化数据降维信息变化程度 plt.plot(np.cumsum(pca.explained_variance_ratio_)) # plt.xlabel(元素数量) # plt.ylabel(可表达信息的百分占比) plt.show() 2.2模型训练及调优 这一段运行起来需要些时间 # 模型训练 # 基本模型训练 xgb XGBClassifier() xgb.fit(x_train_pca,y_train) # 输出预测值一定是输出带有百分比的预测值 y_pre_proba xgb.predict_proba(x_val_pca) # log-loss评估 print(基础训练的log_loss评估值: ,log_loss(y_val, y_pre_proba, eps1e-15, normalizeTrue))# 模型调优 scores_ne [] n_estimators [100,200,300,400,500,550,600,700] for nes in n_estimators:print(n_estimators: ,nes)xgbXGBClassifier(max_depth3,learning_rate0.1,n_estimatorsnes,objectivemulti:softprob,n_jobs-1,nthread4,min_child_weight1,subsample1,colsample_bytree1,seed42)xgb.fit(x_train_pca,y_train)y_pre xgb.predict_proba(x_val_pca)score log_loss(y_val,y_pre)scores_ne.append(score)print(每次测试的log_loss评估值为:{}.format(score)) # 图形化logloss plt.plot(n_estimators,scores_ne,o-) plt.xlabel(n_estimators) plt.ylabel(log_loss) plt.show() print(最优的e_estimators的值是: {}.format(n_estimators[np.argmin(scores_ne)]))# 最优max_depth的调试 scores_md [] max_depths [1,3,5,6,9] for md in max_depths:print(max_depth: ,md)xgbXGBClassifier(max_depthmd,learning_rate0.1,n_estimatorsn_estimators[np.argmin(scores_ne)],objectivemulti:softprob,n_jobs-1,nthread4,min_child_weight1,subsample1,colsample_bytree1,seed42)xgb.fit(x_train_pca,y_train)y_pre xgb.predict_proba(x_val_pca)score log_loss(y_val,y_pre)scores_md.append(score)print(每次测试的log_loss评估值为:{}.format(score)) # 图形化logloss plt.plot(max_depths,scores_md,o-) plt.xlabel(max_depths) plt.ylabel(log_loss) plt.show() print(最优的max_depth的值是: {}.format(max_depths[np.argmin(scores_md)]))# (省略)调优min_child_weights,subsamples,consample_bytrees,etas # 调优后这几个参数为min_child_weight3subsample0.7consample_bytree0.7 # 找到最优参数后 xgb XGBClassifier(max_depth3,learning_rate0.1,n_estimators600,objectivemulti:softprob,nthread4,min_child_weight3,subsample0.7,colsample_bytree0.7,seed42) xgb.fit(x_train_pca,y_train) # y_pre xgb.predict_proba(x_val_scaled) y_pre xgb.predict_proba(x_val_pca) print(测试数据的log_loss值为: {}.format(log_loss(y_val,y_pre,eps1e-15,normalizeTrue)))由于有好几个参数min_child_weights,subsamples,consample_bytrees没有跑没找出最优的值所以最后的log_loss的值还是有些大的。
http://www.zqtcl.cn/news/458133/

相关文章:

  • 长春网络营销网站徐州手机模板建站
  • 微网站开发+在线商城建设局招标网站
  • 网站开发的基本过程关岭做网站
  • 高端网站哪种好WordPress媒体库丢失
  • 澄迈网站新闻建设宣传视频
  • 南昌优化网站排名公司建设网站的步骤
  • 一个人做网站wordpress如何加链接
  • 查网站服务器所在地笔记本电脑安装wordpress
  • 石家庄网站推广专家php网站分类目录源码
  • 盐城市城乡建设局门户网站低代码开发软件
  • 网站建设中的html深圳建设网站需要多少钱
  • 南阳公司网站制作品牌推广工作内容
  • 网站被刷流量怎么办红色php企业网站模板下载
  • 做现货黄金的金融网站设计平台app
  • 淘宝客手机网站搭建网站设计专业公司
  • 做网站用的图片怎样压缩钓鱼网站的制作教程
  • 建设网站类型wordpress竖版图片尺寸
  • 网站建设数据库ER图怎么画公司网站建设建议书
  • 网站建设网站制作有限排名优化课程
  • 绵竹网站建设佛山网络营销推广
  • 网站备案名称重复学会网站建设目的
  • 网站套餐到期什么意思孝感的网站建设
  • 网站制作费用多少钱房地产建筑设计公司
  • 网站优化要素做网站看百度脸色
  • 软件开发 网站开发区别seo怎么刷关键词排名
  • python 网站开发必会智能网站
  • 重庆建设摩托车官方网站网络是干什么的
  • 建筑工程网站源码wordpress 多域名 图片不显示
  • 大型网站建设优化排名wordpress 投稿 插件
  • 二维码的网站如何做静安免费网站制作