Machine Learning 第六波编程作业——Support Vector Machines

仅列出核心代码:

1.gaussianKernel.m

sim = exp(-sum((x1 - x2).^2) /(2*sigma^2));

2.dataset3Params.m

TD =  [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30];
pre_err = zeros(length(TD));
for i = 1:length(TD)
    for j = 1:length(TD)
        C = TD(i);
        sigma = TD(j);
        model= svmTrain(X, y, C, @(x1, x2) gaussianKernel(x1, x2, sigma));
        predictions = svmPredict(model, Xval);
        pre_err(i, j) = mean(double(predictions ~= yval));
    end
end
mm = min(min(pre_err));
[ind_C, ind_sigma] = find(pre_err == mm);
C = TD(ind_C);
sigma = TD(ind_sigma);

3.processEmail.m

for i = 1:length(vocabList)
v = strcmp(str, vocabList(i));
    if v==1
        word_indices = [word_indices ; i];
    end
end

4.emailFeatures.m

x(word_indices) = 1;

课程地址:https://www.coursera.org/course/ml

转载于:https://www.cnblogs.com/andnot/archive/2013/06/11/ml_code6.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值