码迷,mamicode.com
首页 > 其他好文 > 详细

Coursera机器学习week7 编程作业

时间:2018-02-09 23:54:25      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:list   dict   bsp   pre   pos   ams   length   str   作业   

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

  

Coursera机器学习week7 编程作业

标签:list   dict   bsp   pre   pos   ams   length   str   作业   

原文地址:https://www.cnblogs.com/xingkongyihao/p/8436942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!