Azzera filtri
Azzera filtri

How to find the constant value in a loop for a particular condition?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

KALYAN ACHARJYA
KALYAN ACHARJYA il 20 Feb 2021
Modificato: KALYAN ACHARJYA il 20 Feb 2021
"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

Più risposte (0)

Categorie

Scopri di più su Particle & Nuclear Physics in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by