function [ypred, weights] = predictSVM(Xtrain, ytrain, Xtest, C, B, s)

% No more than SVM

if ~exist('s','var')
    s = 1;
end

ytrain = ytrain*2 - 1;

params = sprintf('-s %d -c %f -B %f -q',s,C,B);

nClass = size(ytrain,2);

ypred = zeros(size(Xtest,1),nClass);
ypredtrain = zeros(size(Xtrain,1),nClass);
weights = zeros(size(Xtest,1),nClass);
firstClass = zeros(1,nClass);
for i=1:nClass
    model = train(ytrain(:,i),Xtrain,params);
    %[ypredtrain(:,i),~,~] = predict(ypredtrain(:,i),Xtrain,model);
    
    %fprintf('0pred1true(+): %3d, 1pred0true(-): %3d\n',...
    %        sum(ytrain(:,i)>ypredtrain(:,i)),...
    %        sum(ytrain(:,i)<ypredtrain(:,i)));
    
    %iGood = ytrain(:,i)<=ypredtrain(:,i);
    
    %model = train(ytrain(iGood,i),Xtrain(iGood,:),params);
    [ypred(:,i),~,weights(:,i)] = predict(ypred(:,i),Xtest,model);
    
    firstClass(i) = model.Label(1);
end
ypred = +(ypred>0);
weights=bsxfun(@times,weights,firstClass);