www.gusucode.com > stats 源码程序 matlab案例代码 > stats/PredictTestSampleResponseForSVMRegressionModelExample.m
%% Predict Test Sample Response for SVM Regression Model %% % Load the |carsmall| data set. Consider a model that predicts a car's fuel % efficiency given its horsepower and weight. Determine the sample size. load carsmall tbl = table(Horsepower,Weight,MPG); N = size(tbl,1); %% % Partition the data into training and test sets. Hold out 10% of the data % for testing. rng(10); % For reproducibility cvp = cvpartition(N,'Holdout',0.1); idxTrn = training(cvp); % Training set indices idxTest = test(cvp); % Test set indices %% % Train a linear SVM regression model. Standardize the data. Mdl = fitrsvm(tbl(idxTrn,:),'MPG','Standardize',true); %% % |Mdl| is a |RegressionSVM| model. %% % Predict responses for the test set. YFit = predict(Mdl,tbl(idxTest,:)); %% % Create a table containing the observed response values and the predicted % response values side by side. table(tbl.MPG(idxTest),YFit,'VariableNames',... {'ObservedValue','PredictedValue'})