2 added 1 character in body
source | link

Assuming X is the matrix of new data points (size m x n where each row is an example), you can tackle the problem by considering several kernel.

  1. if your kernel is linear (i.e. dot product)
    The predicted labels can be easily evaluated by
    p = X * model.w + model.b;
    where model.w is an array containing the free parameters of the hyperplane and model.b is the bias.
  2. if your kernel is RBF (i.e. Gaussian)
% square and sum new data points by rows  
X1 = sum(X.^2, 2);  
% square and sum SVs  
X2 = sum(model.SV.^2, 2)';  
% evaluate exponential for RBF formula  
K = bsxfun(@plus, X1, bsxfun(@plus, X2, - 2 * X * model.SV'));  
% evaluate kernel  
K = model.kernelFunction(1, 0) .^ K;  
% multiply Gram matrix by SV labels  
K = bsxfun(@times, model.SVL', K);  
% multiply again by alphas  
K = bsxfun(@times, model.alphas', K);  
% gather final predictions
p = sum(K, 2);

where model.alphas is the Lagrange Multiplier vectors, model.kernelFunction() is the kernel function, model.SV are the Support Vectors and model.SVL are the Support Vectors Labels 3. for an arbitrary kernel, apply the standard rule:

  1. or an arbitrary kernel, apply the standard rule:
for i = 1:m  
    prediction = 0;  
    for j = 1:size(model.SV, 1)  
        prediction = prediction + model.alphas(j) * model.SVL(j) * model.kernelFunction(X(i,:)', model.SV(j,:)');  
    end  
    p(i) = prediction + model.b;  
end

After all that you might want to shrink the predicted labels vector p in a friendly binary format:

predictedLabels(p >= 0) =  1;
predictedLabels(p <  0) =  0;

and predictedLabels is now your final output.

Assuming X is the matrix of new data points (size m x n where each row is an example), you can tackle the problem by considering several kernel.

  1. if your kernel is linear (i.e. dot product)
    The predicted labels can be easily evaluated by
    p = X * model.w + model.b;
    where model.w is an array containing the free parameters of the hyperplane and model.b is the bias.
  2. if your kernel is RBF (i.e. Gaussian)
% square and sum new data points by rows  
X1 = sum(X.^2, 2);  
% square and sum SVs  
X2 = sum(model.SV.^2, 2)';  
% evaluate exponential for RBF formula  
K = bsxfun(@plus, X1, bsxfun(@plus, X2, - 2 * X * model.SV'));  
% evaluate kernel  
K = model.kernelFunction(1, 0) .^ K;  
% multiply Gram matrix by SV labels  
K = bsxfun(@times, model.SVL', K);  
% multiply again by alphas  
K = bsxfun(@times, model.alphas', K);  
% gather final predictions
p = sum(K, 2);

where model.alphas is the Lagrange Multiplier vectors, model.kernelFunction() is the kernel function, model.SV are the Support Vectors and model.SVL are the Support Vectors Labels 3. for an arbitrary kernel, apply the standard rule:

for i = 1:m  
    prediction = 0;  
    for j = 1:size(model.SV, 1)  
        prediction = prediction + model.alphas(j) * model.SVL(j) * model.kernelFunction(X(i,:)', model.SV(j,:)');  
    end  
    p(i) = prediction + model.b;  
end

After all that you might want to shrink the predicted labels vector p in a friendly binary format:

predictedLabels(p >= 0) =  1;
predictedLabels(p <  0) =  0;

and predictedLabels is now your final output.

Assuming X is the matrix of new data points (size m x n where each row is an example), you can tackle the problem by considering several kernel.

  1. if your kernel is linear (i.e. dot product)
    The predicted labels can be easily evaluated by
    p = X * model.w + model.b;
    where model.w is an array containing the free parameters of the hyperplane and model.b is the bias.
  2. if your kernel is RBF (i.e. Gaussian)
% square and sum new data points by rows  
X1 = sum(X.^2, 2);  
% square and sum SVs  
X2 = sum(model.SV.^2, 2)';  
% evaluate exponential for RBF formula  
K = bsxfun(@plus, X1, bsxfun(@plus, X2, - 2 * X * model.SV'));  
% evaluate kernel  
K = model.kernelFunction(1, 0) .^ K;  
% multiply Gram matrix by SV labels  
K = bsxfun(@times, model.SVL', K);  
% multiply again by alphas  
K = bsxfun(@times, model.alphas', K);  
% gather final predictions
p = sum(K, 2);

where model.alphas is the Lagrange Multiplier vectors, model.kernelFunction() is the kernel function, model.SV are the Support Vectors and model.SVL are the Support Vectors Labels

  1. or an arbitrary kernel, apply the standard rule:
for i = 1:m  
    prediction = 0;  
    for j = 1:size(model.SV, 1)  
        prediction = prediction + model.alphas(j) * model.SVL(j) * model.kernelFunction(X(i,:)', model.SV(j,:)');  
    end  
    p(i) = prediction + model.b;  
end

After all that you might want to shrink the predicted labels vector p in a friendly binary format:

predictedLabels(p >= 0) =  1;
predictedLabels(p <  0) =  0;

and predictedLabels is now your final output.

1
source | link

Assuming X is the matrix of new data points (size m x n where each row is an example), you can tackle the problem by considering several kernel.

  1. if your kernel is linear (i.e. dot product)
    The predicted labels can be easily evaluated by
    p = X * model.w + model.b;
    where model.w is an array containing the free parameters of the hyperplane and model.b is the bias.
  2. if your kernel is RBF (i.e. Gaussian)
% square and sum new data points by rows  
X1 = sum(X.^2, 2);  
% square and sum SVs  
X2 = sum(model.SV.^2, 2)';  
% evaluate exponential for RBF formula  
K = bsxfun(@plus, X1, bsxfun(@plus, X2, - 2 * X * model.SV'));  
% evaluate kernel  
K = model.kernelFunction(1, 0) .^ K;  
% multiply Gram matrix by SV labels  
K = bsxfun(@times, model.SVL', K);  
% multiply again by alphas  
K = bsxfun(@times, model.alphas', K);  
% gather final predictions
p = sum(K, 2);

where model.alphas is the Lagrange Multiplier vectors, model.kernelFunction() is the kernel function, model.SV are the Support Vectors and model.SVL are the Support Vectors Labels 3. for an arbitrary kernel, apply the standard rule:

for i = 1:m  
    prediction = 0;  
    for j = 1:size(model.SV, 1)  
        prediction = prediction + model.alphas(j) * model.SVL(j) * model.kernelFunction(X(i,:)', model.SV(j,:)');  
    end  
    p(i) = prediction + model.b;  
end

After all that you might want to shrink the predicted labels vector p in a friendly binary format:

predictedLabels(p >= 0) =  1;
predictedLabels(p <  0) =  0;

and predictedLabels is now your final output.