网格搜索多个监督学习模型上的超参数,包括神经网络、随机森林和树集合模型(Matlab代码实现)

       目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码


💥1 概述

我们在选择超参数有两个途径:1)凭经验;2)选择不同大小的参数,带入到模型中,挑选表现最好的参数。通过途径2选择超参数时,人力手动调节注意力成本太高,非常不值得。For循环或类似于for循环的方法受限于太过分明的层次,不够简洁与灵活,注意力成本高,易出错。GridSearchCV 称为网格搜索交叉验证调参,它通过遍历传入的参数的所有排列组合,通过交叉验证的方式,返回所有参数组合下的评价指标得分。

GridSearchCV听起来很高大上,其实就是暴力搜索。注意的是,该方法在小数据集上很有用,数据集大了就不太适用了。数据量比较大的时候可以使用一个快速调优的方法——坐标下降。它其实是一种贪心算法:拿当前对模型影响最大的参数调优,直到最优化;再拿下一个影响最大的参数调优,如此下去,直到所有的参数调整完毕。这个方法的缺点就是可能会调到局部最优而不是全局最优,但是省时间省力。​​

📚2 运行结果

主函数部分代码:

%% Setup

clear

clc

close all

start_time = tic;

%seed = rng(123);

global want_parellel

%% Inputs

%input_file = 'abalone.csv';

%feature_cols = 1:8;

%ignore_col = 18;

%target_col = 9;

input_file = 'BostonHousePriceDataset.csv';

feature_cols = 1:13;

%ignore_col = 18;

target_col = 14;

want_parellel = false;

val_perc = 0.15;

test_perc = 0.15;

want_all_display =true;

want_final_display = true;

want_plot = true;

%% Get data

table = readtable(input_file, 'PreserveVariableNames', 1);

VarNames = table.Properties.VariableNames';

data_raw = table2array(table);

%%remove ignore cols

%data_raw(:,ignore_col)=[];

%divide data into input and target matricies

x = data_raw(:,feature_cols);

target = data_raw(:,target_col);

%% Prepare the data

%Divide into train and test set

[x_train, x_val, x_test, ind_set] = divide_data(x, val_perc, test_perc);

[t_train, t_val, t_test] = apply_divide_data(target, ind_set);

%% Setup parellel workers

if want_parellel == true

    %open pool of workers

    p=gcp('nocreate');

    if isempty(p)==1

        parpool('local',num_workers);

        p=gcp();

    end

end

🎉3 参考文献

[1]蒋鹏. 小波理论在信号去噪和数据压缩中的应用研究[D].浙江大学,2004.

👨‍💻4 Matlab代码

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值