Why does fitcsvm support 'KFold' models only with fixed hyper-parameters?

1 Ansicht (letzte 30 Tage)
normanius
normanius am 8 Mai 2018
Kommentiert: Don Mathis am 11 Mai 2018
I would like to train a KFold model with modified hyper-parameters.
The following works:
cvModel = fitcsvm(XTrain, yTrain, ...
'KernelFunction', kernelType, ...
'Weights', weights, ...
'KFold', nPartitions);
However, the following does not:
cvModel = fitcsvm(XTrain, yTrain, ...
'KernelFunction', kernelType, ...
'BoxConstraint', boxConstraint, ...
'KernelScale', kernelScale, ...
'PolynomialOrder', polynomialOrder, ...
'Weights', weights, ...
'KFold', nPartitions);
A model is trained, so the function completes without error, but it is not KFold. In the documentation , I noticed the following: To create a cross-validated model, you can use one of these four name-value pair arguments only: CVPartition, Holdout, KFold, or Leaveout.
So it is not allowed to use any other options than those named. How can I set BoxConstraint, KernelScale and other parameters and still yield a KFold model? It does not make sense to me at all why this should be prohibited!
Thanks for any support!
  1 Kommentar
Don Mathis
Don Mathis am 11 Mai 2018
I can't replicate your results. When I run your second code, I get a partitioned model.
Running this:
XTrain = rand(100,3);
yTrain = categorical(rand(100,1)>.5);
kernelType = 'polynomial';
boxConstraint = 1;
kernelScale = 1;
polynomialOrder = 2;
weights = rand(100,1);
nPartitions = 3;
cvModel = fitcsvm(XTrain, yTrain, ...
'KernelFunction', kernelType, ...
'BoxConstraint', boxConstraint, ...
'KernelScale', kernelScale, ...
'PolynomialOrder', polynomialOrder, ...
'Weights', weights, ...
'KFold', nPartitions)
Outputs this:
cvModel =
classreg.learning.partition.ClassificationPartitionedModel
CrossValidatedModel: 'SVM'
PredictorNames: {'x1' 'x2' 'x3'}
ResponseName: 'Y'
NumObservations: 100
KFold: 3
Partition: [1×1 cvpartition]
ClassNames: [false true]
ScoreTransform: 'none'
Properties, Methods

Melden Sie sich an, um zu kommentieren.

Antworten (1)

normanius
normanius am 8 Mai 2018
A very related question: is the following equivalent?
cvModel1 = fitcsvm(XTrain, yTrain, ...
'KernelFunction', kernelType, ...
'Weights', weights, ...
'KFold', nPartitions);
cvModel2 = fitcsvm(XTrain, yTrain, ...
'KernelFunction', kernelType, ...
'Weights', weights);
cvModel2 = crossval(cvModel2, 'KFold', nPartitions);
In case cvModel1 and cvModel2 were equivalent, this would be the answer to my question.

Community Treasure Hunt

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

Start Hunting!

Translated by