gaussianKernel.m
sim = exp(-sum((x1-x2).^2)/(sigma.^2*2));
dataset3Params.m
steps = [0.01,0.03,0.1,0.3,1,3,10,30]; minError = Inf; minC = Inf; minSigma = Inf; for i = 1:length(steps) for j = 1:length(steps) currC = steps(i); currSigma = steps(j); model = svmTrain(X, y, currC, @(x1, x2) gaussianKernel(x1, x2, currSigma)); predictions = svmPredict(model, Xval); error = mean(double(predictions ~= yval)); if(error < minError) minError = error; minC = currC; minSigma = currSigma; end end end C = minC; sigma = minSigma;
processEmail.m
for i = 1:length(vocabList) if(strcmp(vocabList(i), str)) word_indices = [word_indices; i] break; end end
emailFeatures.m
for i = 1:length(word_indices) x(word_indices(i)) = 1 end