Predict Test Sample Response for SVM Regression Model

2 views (last 30 days)
Hi
I am running test on data samples using the example of SVM Regression Model, in the case of the example given in this MathWorks documentation (link) the training data needs to have the same number of rows as the predict data, this is required so far to be able to run the prediction. What can I do if my data varies from the number of rows? How can I train my support vector machine with a data that have diferent number of samples and still be able to predict with the consequence of having maybe bigger error?
Data sample of the training data for the model and the data that I want to use for Mdl = fitrsvm.
ans=10×2 table
Training data Data to predict
_____________ ______________
14 9.4833
27 28.938
10 7.765
28
22 21.054
29 31.484
24.5 30.306
18.5
32 28.225
28

Answers (1)

Bhargavi Maganuru
Bhargavi Maganuru on 11 Sep 2019
You can make changes in the example given in MathWorks documentation page to use different data which has different number of samples.
load carsmall
tbl = table(Horsepower,Weight,MPG);
N = size(tbl,1);
Instead of using carsmall dataset you can load your own dataset.
rng(10); % For reproducibility
cvp = cvpartition(N,'Holdout',0.1);
idxTrn = training(cvp); % Training set indices
idxTest = test(cvp); % Test set indices
You can partition your own data into training data and the testing data using cvpartition(N,’HoldOut’,p) by setting p to get p*N number of test samples.
Also ObservedValuevariable in the ans table is the actual target value for the test data and the PredictedValue variable in the ans table is the predicted value for the test data.
  1 Comment
antlhem
antlhem on 16 Sep 2019
Edited: antlhem on 16 Sep 2019
Thank you for your reply. So far I have managed to train my SVM model modifying data from carsmall. But my question remains because, the YFit = predict(Mdl,tbl(idxTest,:)); asks all the time to have the same number of samples as the train sample. My question is. How to use the trained model for samples that were not in the training table? I would like to use trending of the model as well to predict the data that were not initially in the training model, like the table below. How to achieve this?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!