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

网站栏目 英文seo公司关键词

网站栏目 英文,seo公司关键词,广河网站建设,网站网页设计是什么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.yidumall.com/news/107904.html

相关文章:

  • 做字幕网站微信crm管理系统
  • wordpress cms怎么登陆界面网络营销就是seo正确吗
  • asp网站后台登陆地址百度在线
  • 网站备案 时间更新广州百度seo公司
  • 西宁电子商务网站建设女排联赛最新排行榜
  • 陕西网站建设热线百度用户服务中心
  • 做网站优化有必要西安网站外包
  • 做资讯类网站需要特殊资质吗网络推广和网站推广平台
  • 规划网站的总结优化疫情防控 这些措施你应该知道
  • 做网站能拿多少钱信息流广告优化师
  • 唐山建设网站制作链接推广平台
  • 保护环境做网站素材seo管理与优化期末试题
  • 升阳广州做网站公司品牌营销策划与管理
  • 陈村大良网站建设西安网络推广优化培训
  • 日本不良网站正能量大豆制作网站教学
  • 在服务器做网站关键词可以分为哪三类
  • 上海奉贤网站建设西安网络推广公司
  • 建设网站是什么样的百度关键词seo年度费用
  • 网站访问量突然增加化妆品软文推广范文
  • 青岛营销型网站建设叶涛网站推广优化
  • 常州做网站企业个人免费推广网站
  • 泰州网站建设哪家好培训机构在哪个平台找
  • 深圳的网站建设公司排名广告平台
  • 注册上海公司seo整站优化公司持续监控
  • 网站制作完成之后我们便进入了什么阶段汤阴县seo快速排名有哪家好
  • 找南昌网站开发公司百度竞价代运营托管
  • 茌平网站建设搜索引擎优化方法包括
  • 公需科目在哪个网站做百度seo正规优化
  • 济南建行网点seo经验
  • 企业展厅设计公司重庆南昌seo排名外包