How to find the constant value in a loop for a particular condition?
1 次查看(过去 30 天)
显示 更早的评论
A = [0.01; 0.03; 0.1; 0.3; 1; 3; 10; 30];
% error = zeros(64,1);
for i= 1:8
C = A(i);
for j = 1:8
sigma = A(j);
model= svmTrain(X, y, C, @(x1, x2) gaussianKernel(x1, x2, sigma));
predictions = svmPredict(model, Xval);
error(i,j) = mean(double(predictions ~= yval));
end
end
[p,q] = find(error == min(error(:)));
error gives me a 8x8 matrix. when I find minimum value of the matrix , it turns out that [5,3] indices of the matrix gives me the minimum value. Although I can find the corresponding C and sigma value manually as dimension of A is small. but if it is of high dimension then it is hard to find that. I just want to find out corresponding C and sigma value for which I get minimum value in the error matrix automatically.
0 个评论
采纳的回答
KALYAN ACHARJYA
2021-2-20
编辑:KALYAN ACHARJYA
2021-2-20
"I just want to find out corresponding C and sigma value for which I get minimum value in the error matrix automatically"
for i= 1:8
for j = 1:8
model= svmTrain(X, y, C, @(x1, x2) gaussianKernel(x1, x2, sigma));
predictions = svmPredict(model, Xval);
error(i,j) = mean(double(predictions ~= yval));
end
end
As you have complete the iterations to find the error matrix, once you done that, find the indices (i and j) of minimum of error matrix.
[i,j] = find(error==min(error(:)));
Now get the corresponding C and sigma
C=A(i)
sigma=A(j)
Note that, if you have mutiple minimum same value in the matrix, you may get multiple indices of i and j
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!