# 机器学习——最小二乘分类

clear; closeall; clc;

n = 200;

a = linspace(0,4*pi,n/2);

u = [a.*cos(a) (a+pi).*cos(a)]' + rand(n,1);

v = [a.*sin(a) (a+pi).*sin(a)]' + rand(n,1);

x = [u v];

y = [ones(1,n/2) -ones(1,n/2)]';

x2 = sum(x.^2,2);

hh = 2*1^2;

l = 0.01;

k = exp(-(repmat(x2,1,n) + repmat(x2',n,1) - 2*x*x')/hh);

t = (k^2 + l*eye(n))\(k*y);

m = 100;

X = linspace(-15,15,m)';

X2 = X.^2;

U = exp(-(repmat(u.^2,1,m) + repmat(X2',n,1) - 2*u*X')/hh);

V = exp(-(repmat(v.^2,1,m) + repmat(X2',n,1) - 2*v*X')/hh);

holdon

contourf(X,X,sign(V'*(U.*repmat(t,1,m))));

plot(x(y==1,1),x(y==1,2),'bo','MarkerSize',8,'linewidth',2.5);

plot(x(y==-1,1),x(y==-1,2),'rx','MarkerSize',8,'linewidth',2.5);

axis([-15,15,-15,15]);

colormap([1 0.7 1; 0.7 1 1]);

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20180408G1SGAT00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2022-07-05

2022-07-05

2022-07-05

2022-07-05

2022-07-05

2018-03-30

2018-07-04

2018-05-15

2022-07-05

2022-07-05

2022-07-05

2022-07-05