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

    %% Compute the Cross-Validation Error
% Compute the cross-validation error for a default regression tree.
%%
% Load the |carsmall| data set. Consider |Displacement|, |Horsepower|, and
% |Weight| as predictors of the response |MPG|.

% Copyright 2015 The MathWorks, Inc.

load carsmall
X = [Displacement Horsepower Weight];
%%
% Grow a regression tree using the entire data set.
Mdl = fitrtree(X,MPG);
%%
% Compute the cross-validation error.
rng(1); % For reproducibility
E = cvloss(Mdl)
%%
% |E| is the 10-fold weighted, averge MSE (weighted by number of test
% observations in the folds).