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

    %% Optimize Linear Classifier
% This example shows how to minimize the cross-validation error in a linear
% classifier using |fitclinear|. The example uses the NLP data set.
%%
% Load the NLP data set.
load nlpdata
%%
% |X| is a sparse matrix of predictor data, and |Y| is a categorical vector
% of class labels. There are more than two classes in the data.
% 
% The models should identify whether the word counts in a web page are from
% the Statistics and Machine Learning Toolbox™ documentation.
% Identify the relevant labels.
X = X';
Ystats = Y == 'stats';
%%
% Optimize the classification using the |'auto'| parameters.
%
% For reproducibility, set the random seed and use the
% |'expected-improvement-plus'| acquisition function.
rng default
Mdl = fitclinear(X,Ystats,'ObservationsIn','columns','Solver','sparsa',...
    'OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',...
    struct('AcquisitionFunctionName','expected-improvement-plus'))