필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
normanius
normanius 2018년 5월 8일
댓글: Don Mathis 2018년 5월 11일
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
Don Mathis
Don Mathis 2018년 5월 11일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

normanius
normanius 2018년 5월 8일
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