用CVX实现SVM
2016-03-23 14:59
453 查看
% get SVM data load fisheriris classKeep = ~strcmp(species,'virginica'); X = meas(classKeep,3:4); y = species(classKeep); gscatter(X(:,1),X(:,2),y,'mc','.x',[15,10]); classKeep = strcmp(y , 'setosa'); y = double(classKeep); ind = find(y == 0); y(ind) = -1; % train SVM n = size(X,2); cvx_begin variable w(n); variable b; minimize( 1/2*norm(w) ); subject to y.*( X * w + b) -1 >= 0; cvx_end % find support vector out = y.*( X * w + b); out=round(out*100)/100; ind = find( out == 1); % draw support vector figure,gscatter(X(:,1),X(:,2),y,'mc','.x',[15,10]); hold on plot([0 -b/(w(1))],[-b/(w(2)) 0],'b') hold on for i = 1:length(ind) gscatter(X(ind(i),1),X(ind(i),2),'xo'); end
相关文章推荐
- 第45次全国计算机等级考试上机考试黄金校区安排表
- OC字符串基本操作
- 如何将java程序包打包成.exe文件,在没有安装jre的windows上运行
- 基本JS表单验证封装类
- Can't find X includes. Please check your installation and add the correct paths! 4000
- Centos6.5 卸载mysql
- label控件--关于价格显示中划线和下划线
- twisted转载二即异步编程初探与reactor模式
- QTimer调用Stop后再次start,以前connect的槽将失效
- Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等
- HDOJ1195 Open the Lock
- hihoCoder 1133 二分·二分查找之k小数
- 移动端JS调用QQ,拨打电话,发送短信
- iOS 网络问题
- iOS 宏(define)与常量(const)使用
- 整流二极管
- Gridview样式的CSS控制
- struts配置找不到正确的action时所要跳转的action
- 使用git有感
- 题目类型整理