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

河南视频网站建设公司优化设计方案

河南视频网站建设公司,优化设计方案,有一个网站 人物模型可以做各种动作,徐州手机网站制作1. 随机森林超参数 极其重要的三个超参数是必须要调整的,一般再加上两到三个其他超参数进行优化即可。 2. 学习曲线确定n_estimators搜索范围 首先导入必要的库,使用sklearn自带的房价预测数据集: import numpy as np import pandas as pd f…

1. 随机森林超参数

        极其重要的三个超参数是必须要调整的,一般再加上两到三个其他超参数进行优化即可。

2. 学习曲线确定n_estimators搜索范围

        首先导入必要的库,使用sklearn自带的房价预测数据集:

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.datasets import fetch_california_housing
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_validate
import matplotlib.pyplot as plt
housing = fetch_california_housing()
# 特征数据
X = housing.data[:, [0, 1, 2, 3, 4, 5, 6, 7]]
# 目标变量(房价)
y = housing.target

        初始化以及5折交叉验证计算RMSE:

trainRMSE = np.array([])
testRMSE = np.array([])
trainSTD = np.array([])
testSTD = np.array([])Option = range(5,101,5)
for n_estimators in Option :reg_f = RandomForestRegressor(n_estimators=n_estimators, random_state=1412)# 交叉验证输出结果cv = KFold(n_splits=5,shuffle=True,random_state=1412)result_f = cross_validate(reg_f,X,y,cv=cv,scoring="neg_mean_squared_error",return_train_score=True,n_jobs=-1)# 根据输出的MSE进行RMSE计算train = abs(result_f["train_score"])**0.5test = abs(result_f["test_score"])**0.5trainRMSE = np.append(trainRMSE,train.mean())testRMSE = np.append(testRMSE,test.mean())trainSTD = np.append(trainSTD,train.std())testSTD = np.append(testSTD,test.std())

        定义绘图函数: 

def plotCVresult(Option,trainRMSE,testRMSE,trainSTD,testSTD) :xaxis = Option# RMSEplt.plot(xaxis, trainRMSE,color='k',label='RandomForestTrain')plt.plot(xaxis, testRMSE, color='red', label='RandomForestTest')# 将标准差围绕在RMSE旁边,区间越大表示模型越不稳定plt.plot(xaxis, trainRMSE + trainSTD, color='k', linestyle='dotted')plt.plot(xaxis, trainRMSE - trainSTD, color='k', linestyle='dotted')plt.plot(xaxis, testRMSE + testSTD, color='red', linestyle='dotted')plt.plot(xaxis, testRMSE - testSTD, color='red', linestyle='dotted')plt.xticks([*xaxis])plt.legend(loc=1)plt.xlabel('n_estimators')plt.ylabel('RMSE')plt.title('Learning Curve')plt.show()plotCVresult(Option,trainRMSE,testRMSE,trainSTD,testSTD)

        输出结果如下: 

 3. 使用Tree模块判断max_depth搜索范围

        只需在输出的最小值和最大值之间进行搜索即可。

reg_f = RandomForestRegressor(n_estimators=100,random_state=1412)
reg_f = reg_f.fit(X,y)
d = pd.Series([],dtype="int64")
for idx,t in enumerate(reg_f.estimators_) :d[idx] = t.tree_.max_depth
print('决策树的最大深度的最小值为:',d.min())
print('决策树的最大深度的最大值为:',d.max())

        输出结果为:

4. 使用Tree模块判断min_weight_fraction_leaf搜索范围

reg_f = RandomForestRegressor(n_estimators=100,random_state=1412)
reg_f = reg_f.fit(X,y)
n = pd.Series([],dtype="int64")
for idx,t in enumerate(reg_f.estimators_) :n[idx] = t.tree_.weighted_n_node_samples
meann = np.zeros(20)
for i in range(0,20) :meann[i] = n[i].mean()
print('决策树分枝所需最小样本权重的最小值为:',meann.min())
print('决策树分枝所需最小样本权重的最大值为:',meann.max())
print('决策树分枝所需最小样本权重的平均值为:',meann.mean())

        输出结果为:

 5. 使用Tree模块判断min_sample_split搜索范围

reg_f = RandomForestRegressor(n_estimators=20,random_state=1412)
reg_f = reg_f.fit(X,y)
s = pd.Series([],dtype="int64")
for idx,t in enumerate(reg_f.estimators_) :s[idx] = t.tree_.n_node_samples
meann = np.zeros(20)
for i in range(0,20) :meann[i] = s[i].mean()
print('决策树需要最小样本的最小值为:',meann.min())
print('决策树需要最小样本的最大值为:',meann.max())
print('决策树需要最小样本的平均值为:',meann.mean())

        输出结果为:

 

 

http://www.hkea.cn/news/205551/

相关文章:

  • 怎么做外贸网站的邮箱签名搜索引擎优化是指什么
  • 网页制作基础教程免费邯郸网站seo
  • phpcms做网站感想漯河seo推广
  • 公司部门kpi绩效考核指标模板河北百度seo软件
  • 印团网网站是哪家做的唯尚广告联盟
  • 网红营销网站seo综合查询怎么用的
  • 西安地区网站建设云推广
  • wordpress个人站2020年关键词排名
  • 网站建设企业公司石家庄新闻头条新闻最新今天
  • 道滘镇做网站百度统计
  • qq空间做宣传网站怎样建立自己的网站平台
  • 做设计一般用的素材网站是什么意思刷网站排名软件
  • 帮人做兼职的网站吗青岛seo服务哪家好
  • 贷款类网站怎样做网络营销的推广
  • 乐清做网站哪家好税收大数据
  • 校园网站建设需求天津放心站内优化seo
  • 哈尔滨微网站建设热搜在哪里可以看
  • 网站用oracle做数据库福州seo推广服务
  • 康保县城乡建设委员会网站营销型网站重要特点是
  • 手机做网站的步骤跨境电商有哪些平台
  • 请人做网站要多少网络事件营销
  • 网站页脚有什么作用厦门seo哪家强
  • 东莞百度提升优化优化推广网站推荐
  • 查企业网站有哪些站长统计app软件
  • 做a高清视频在线观看网站济源新站seo关键词排名推广
  • 刚做的网站怎么搜索不出来百度seo收录软件
  • 视频拍摄app站长工具seo综合查询广告
  • 新闻单位建设网站的意义武汉seo推广优化
  • 低价网站公司软文怎么写
  • 东莞市建设公共交易中心网站百度官网首页