www.gusucode.com > stats 源码程序 matlab案例代码 > stats/OptimizeARegressionTreeExample.m

    %% Optimize Regression Tree
% This example shows how to optimize hyperparameters automatically using
% |fitrtree|. The example uses the |carsmall| data.
%%
% Load the |carsmall| data.
load carsmall
%%
% Use |Weight| and |Horsepower| as predictors for |MPG|. Find
% hyperparameters that minimize five-fold cross-validation loss by using
% automatic hyperparameter optimization.
%
% For reproducibility, set the random seed and use the
% |'expected-improvement-plus'| acquisition function.
X = [Weight,Horsepower];
Y = MPG;
rng default
Mdl = fitrtree(X,Y,'OptimizeHyperparameters','auto',...
    'HyperparameterOptimizationOptions',struct('AcquisitionFunctionName',...
    'expected-improvement-plus'))