作业 用身高/体重数据进行性别分类的实验(二)
答案:1 悬赏:30 手机版
解决时间 2021-11-30 10:08
- 提问者网友:鐵馬踏冰河
- 2021-11-30 05:04
作业 用身高/体重数据进行性别分类的实验(二)
最佳答案
- 五星知识达人网友:往事埋风中
- 2021-11-30 06:20
clear all;
a=[171 53
168 57
160 58
161 45
153 51
160 53
165 53.2
163 44
164 55
160 50.5
161 50
154 63
152 50
166 52
165 55
183 67
165 57.5
169 57.1
170 60
163 47
165 50
160 51
140 46
170 60
171 57
164 55
149 50
167 57
165 57
163 44
163 50
166 60
166 47
168 57
160 50
163 47.5
157 50
163 51
169 50
167 54
165 52
157 46
163 50
162 53
153 65
166 55
170 56
160 45
157 40
160 46];
b=[175 68
176 73
187 70
172 70
174 69
164 53
175 59
180 63
176 80
180 70
178 65
175 60
175 70
173 60
177 58
168 56
170 57
175 65
178 77
165 56
170 57.5
168 55.1
169 65
178 67
179 68.5
172 55
172 65
170 57
165 55
177 70
170 68
175 66
172 60
178 69
176 66
167 60
178 90
173 65
171 68
180 72
173 60
180 80
169 60
171 58
174 65
176 66
174 68
171 66
180 84
175 70];
F=1;M=2;
t=[160 46 F
165 49 F
170 55 F
160 50 F
156 45 F
163 50 F
160 60 F
163 55 F
161 47 F
160 47 F
160 47 F
160 48 F
169 48 F
160 47 F
155 60 F
160 60 F
173 64 F
160 67 F
155 55 F
160 50 F
168 48 F
160 45 F
162 52 F
157 54 F
166 55 F
162 43 F
160 53 F
163 48 F
164 46 F
162 44 F
155 48 F
173 54 F
168 53 F
163 57 F
155 48 F
155 40 F
163 46 F
155 41 F
167 55 F
164 55 F
161 45 F
160 60 F
156 49 F
163 50 F
166 47 F
168 57 F
160 50 F
163 47.5 F
157 50 F
163 51 F
178 84 M
173 67 M
185 100 M
165 65 M
173 70 M
178 62 M
173 64 M
175 62.5 M
170 55 M
170 51 M
170 50 M
170 58 M
176 68 M
178 80 M
174 64 M
175 60 M
175 70 M
178 63 M
175 64 M
175 82 M
182 68 M
169 58 M
173 60 M
170 62 M
178 68 M
178 85 M
170 70 M
173 65 M
168 52 M
168 77 M
170 70 M
175 64 M
172 69 M
175 70 M
173 70 M
180 80 M
166 58 M
173 60 M
183 77 M
174 65 M
176 62 M
186 75 M
170 58 M
170 65 M
178 60 M
168 75 M
175 70 M
171 65 M
170 70 M
170 65 M
168 66 M
175 68 M
175 66 M
180 65 M
172 70 M
180 66 M
173 67 M
171 65 M
175 67 M
174 62 M
172 63 M
178 95 M
173 65 M
165 62 M
168 50 M
174 66 M
170 65 M
168 70 M
178 75 M
181 58 M
179 60 M
176 71 M
180 68 M
176 65 M
172 57 M
175 60 M
165 60 M
178 66 M
181.5 83 M
171 53 M
172 63 M
170 54 M
165 53 M
185 73 M
177 60 M
170 55 M
176 69 M
178 62 M
182 63 M
170 80 M
180 100 M
179.5 75 M
173 65 M
178 73 M
173 55 M
180 71 M
171 64 M
178 69 M
184 64 M
180 80 M
176 70 M
169 65 M
170 60 M
176 72 M
187 78 M
176 75 M
185 65 M
178 75 M
172 61 M
180 85 M
186 88 M
167 50 M
174 75 M
170 60 M
183 80 M
173 65 M
180 55 M
183 65 M
178 80 M
178 65 M
168 64 M
171 68 M
170 60 M
173 60 M
173 60 M
173 70 M
175 60 M
181 70 M
180 67 M
175 65 M
178 73 M
190 85 M
178 74 M
168 63 M
172 63 M
181 67 M
185 76 M
186 74 M
169 60 M
178 90 M
178 70 M
176 58 M
174 68 M
178 60 M
176 72 M
180 65 M
175 65 M
182 60 M
172 65 M
170 65 M
168 53 M
174 65 M
178 68 M
177 68 M
174 62 M
175 65 M
172 82 M
193 90 M
174 78 M
178 65 M
174 55 M
179 70 M
189 78 M
176 62 M
172 82 M
174 85 M
171 55 M
178 66 M
177 65 M
174 70 M
186 72 M
172 50 M
175 60 M
175 75 M
177 70 M
170 75 M
175 60 M
173 75 M
179 85 M
173 100 M
170 77 M
170 55 M
174 68 M
173 125 M
178 63 M
171 55 M
165 55 M
189 74 M
173 65 M
167 62 M
169 52 M
170 60 M
176 72 M
176 65 M
175 66 M
174 54 M
173 65 M
173 63 M
178 65 M
179 67 M
182 65 M
165 65 M
186 78 M
162 50 M
163 55 M
186 75 M
178 90 M
180 67.5 M
170 65 M
174 80 M
173 84 M
174 66 M
177 59.5 M
163 52 M
177 64 M
175 70 M
169 56 M
178 60 M
173 55 M
183 73 M
170 62 M
169 73 M
183 60 M
162 56.5 M
178 68 M
178 65 M
168 56 M
173 56 M
179 63 M
179 80 M
170 75 M
172 69 M
175 70 M
178 65 M
179 74 M
171 75 M
180 60 M
175 60 M
170 58 M
185 68.5 M
175 64 M
173 60 M
172 70 M
177 65 M
182 72 M
172 70 M
177 58 M
175 60 M
175 68 M
173 63 M];
% 1.parzen窗法()
h=0.5*sqrt(50);
v=h/sqrt(50);
sum1=0;
sum2=0;
g=zeros(1,300);
for j=1:300
for i=1:50
sum1=sum1+exp(-0.5*((t(j,1)-a(i,1))/v)^2);
sum2=sum2+exp(-0.5*((t(j,1)-b(i,1))/v)^2);
end
if sum1>(sum2*5)
g(1,j)=1;
elseif sum1<(sum2*5)
g(1,j)=2;
elseif sum1==(sum2*5)
g(1,j)=0;
end
end
s1=0;s2=0;
for i=1:50
if g(1,i)~=1;
s1=s1+1;
end
end
s1;
for j=51:300
if g(1,j)~=2;
s2=s2+1;
end
end
s2;
% 2.Fiher线性判别法
x1=sum(a)/50;
x2=sum(b)/50;
ss1=zeros(2,2);ss2=zeros(2,2);
for i=1:50
ss1=ss1+(a(i,:)-x1)'*(a(i,:)-x1);
ss2=ss2+(b(i,:)-x2)'*(a(i,:)-x2);
end
sss=ss1+ss2;w=zeros(2,1);
w=inv(sss)*(x1-x2)';
y1=w'*x1';
y2=w'*x2';
w0=(y1+y2)/2;
sh1=zeros(1,50);sh2=zeros(1,50);
for i=1:50
if w'*a(i,:)'>w0
sh1(i)=1;
end
if w'*a(i,:)' sh1(i)=2;
end
if w'*a(i,:)'==w0
sh1(i)=0;
end
end
for i=1:50
if w'*b(i,:)'>w0
sh2(i)=1;
elseif w'*b(i,:)' sh2(i)=2;
else
sh2(i)=0;
end
end
u1=0;u2=0;
for i=1:50
if sh1(i)~=1
u1=u1+1;
end
if sh2(i)~=2
u2=u2+1;
end
end
u1;
u2;
%测试样本
x3=sum(t(1:50,1:2))/50;
x4=sum(t(51:300,1:2))/250;
sss1=zeros(2,2);sss2=zeros(2,2);
for i=1:50
sss1=sss1+(t(i,1:2)-x3)'*(t(i,1:2)-x3);
end
for i=51:300
sss2=sss2+(t(i,1:2)-x4)'*(t(i,1:2)-x4);
end
ssss=sss1+sss2;ww=zeros(2,1);
ww=inv(ssss)*(x3-x4)';
y3=ww'*x3';
y4=ww'*x4';
ww0=(y3+y4)/2;
sh3=zeros(1,300);
for i=1:50
if ww'*t(i,1:2)'>ww0
sh3(i)=1;
elseif ww'*t(i,1:2)' sh3(i)=2;
else
sh3(i)=0;
end
end
for i=51:300
if ww'*t(i,1:2)'>ww0
sh3(i)=1;
elseif ww'*t(i,1:2)' sh3(i)=2;
else
sh3(i)=0;
end
end
u3=0;u4=0;
for i=1:50
if sh3(i)~=1
u3=u3+1;
end
end
for i=51:300
if sh3(i)~=2
u4=u4+1;
end
end
u3;
u4;
%留一法(parzen窗法)
h1=0.5*sqrt(50);
v1=h1/sqrt(49);
h2=0.5*sqrt(50);
v2=h2/sqrt(50);
su1=0;
su2=0;
su3=0;
su4=0;
su5=0;
su6=0;
su7=0;
su8=0;
g1=zeros(1,50);g2=zeros(1,50);
for j=1:50
for i=1:50
su1=su1+exp(-0.5*((a(j,1)-a(i,1))/v1)^2);
su2=su2+exp(-0.5*((a(j,1)-b(i,1))/v2)^2);
end
su1=(su1-1)/sqrt(49);
su2=su2/sqrt(50);
if su1>(su2*50/49)
g1(1,j)=1;
elseif su1<(su2*50/49)
g1(1,j)=2;
elseif su1==(su2*50/49)
g1(1,j)=0;
end
end
for j=1:50
for i=1:50
su3=su1+exp(-0.5*((b(j,1)-a(i,1))/v2)^2);
su4=su4+exp(-0.5*((b(j,1)-b(i,1))/v1)^2);
end
su3=su3/sqrt(50);
su4=(su4-1)/sqrt(49);
if su3>(su4*49/50)
g2(1,j)=1;
elseif su3<(su4*49/50)
g2(1,j)=2;
elseif su3==(su4*49/50)
g2(1,j)=0;
end
end
ss1=0;ss2=0;
for i=1:50
if g1(1,i)~=1;
ss1=ss1+1;
end
end
ss1
for j=1:50
if g2(1,j)~=2;
ss2=ss2+1;
end
end
ss2参考资料:张绍武
a=[171 53
168 57
160 58
161 45
153 51
160 53
165 53.2
163 44
164 55
160 50.5
161 50
154 63
152 50
166 52
165 55
183 67
165 57.5
169 57.1
170 60
163 47
165 50
160 51
140 46
170 60
171 57
164 55
149 50
167 57
165 57
163 44
163 50
166 60
166 47
168 57
160 50
163 47.5
157 50
163 51
169 50
167 54
165 52
157 46
163 50
162 53
153 65
166 55
170 56
160 45
157 40
160 46];
b=[175 68
176 73
187 70
172 70
174 69
164 53
175 59
180 63
176 80
180 70
178 65
175 60
175 70
173 60
177 58
168 56
170 57
175 65
178 77
165 56
170 57.5
168 55.1
169 65
178 67
179 68.5
172 55
172 65
170 57
165 55
177 70
170 68
175 66
172 60
178 69
176 66
167 60
178 90
173 65
171 68
180 72
173 60
180 80
169 60
171 58
174 65
176 66
174 68
171 66
180 84
175 70];
F=1;M=2;
t=[160 46 F
165 49 F
170 55 F
160 50 F
156 45 F
163 50 F
160 60 F
163 55 F
161 47 F
160 47 F
160 47 F
160 48 F
169 48 F
160 47 F
155 60 F
160 60 F
173 64 F
160 67 F
155 55 F
160 50 F
168 48 F
160 45 F
162 52 F
157 54 F
166 55 F
162 43 F
160 53 F
163 48 F
164 46 F
162 44 F
155 48 F
173 54 F
168 53 F
163 57 F
155 48 F
155 40 F
163 46 F
155 41 F
167 55 F
164 55 F
161 45 F
160 60 F
156 49 F
163 50 F
166 47 F
168 57 F
160 50 F
163 47.5 F
157 50 F
163 51 F
178 84 M
173 67 M
185 100 M
165 65 M
173 70 M
178 62 M
173 64 M
175 62.5 M
170 55 M
170 51 M
170 50 M
170 58 M
176 68 M
178 80 M
174 64 M
175 60 M
175 70 M
178 63 M
175 64 M
175 82 M
182 68 M
169 58 M
173 60 M
170 62 M
178 68 M
178 85 M
170 70 M
173 65 M
168 52 M
168 77 M
170 70 M
175 64 M
172 69 M
175 70 M
173 70 M
180 80 M
166 58 M
173 60 M
183 77 M
174 65 M
176 62 M
186 75 M
170 58 M
170 65 M
178 60 M
168 75 M
175 70 M
171 65 M
170 70 M
170 65 M
168 66 M
175 68 M
175 66 M
180 65 M
172 70 M
180 66 M
173 67 M
171 65 M
175 67 M
174 62 M
172 63 M
178 95 M
173 65 M
165 62 M
168 50 M
174 66 M
170 65 M
168 70 M
178 75 M
181 58 M
179 60 M
176 71 M
180 68 M
176 65 M
172 57 M
175 60 M
165 60 M
178 66 M
181.5 83 M
171 53 M
172 63 M
170 54 M
165 53 M
185 73 M
177 60 M
170 55 M
176 69 M
178 62 M
182 63 M
170 80 M
180 100 M
179.5 75 M
173 65 M
178 73 M
173 55 M
180 71 M
171 64 M
178 69 M
184 64 M
180 80 M
176 70 M
169 65 M
170 60 M
176 72 M
187 78 M
176 75 M
185 65 M
178 75 M
172 61 M
180 85 M
186 88 M
167 50 M
174 75 M
170 60 M
183 80 M
173 65 M
180 55 M
183 65 M
178 80 M
178 65 M
168 64 M
171 68 M
170 60 M
173 60 M
173 60 M
173 70 M
175 60 M
181 70 M
180 67 M
175 65 M
178 73 M
190 85 M
178 74 M
168 63 M
172 63 M
181 67 M
185 76 M
186 74 M
169 60 M
178 90 M
178 70 M
176 58 M
174 68 M
178 60 M
176 72 M
180 65 M
175 65 M
182 60 M
172 65 M
170 65 M
168 53 M
174 65 M
178 68 M
177 68 M
174 62 M
175 65 M
172 82 M
193 90 M
174 78 M
178 65 M
174 55 M
179 70 M
189 78 M
176 62 M
172 82 M
174 85 M
171 55 M
178 66 M
177 65 M
174 70 M
186 72 M
172 50 M
175 60 M
175 75 M
177 70 M
170 75 M
175 60 M
173 75 M
179 85 M
173 100 M
170 77 M
170 55 M
174 68 M
173 125 M
178 63 M
171 55 M
165 55 M
189 74 M
173 65 M
167 62 M
169 52 M
170 60 M
176 72 M
176 65 M
175 66 M
174 54 M
173 65 M
173 63 M
178 65 M
179 67 M
182 65 M
165 65 M
186 78 M
162 50 M
163 55 M
186 75 M
178 90 M
180 67.5 M
170 65 M
174 80 M
173 84 M
174 66 M
177 59.5 M
163 52 M
177 64 M
175 70 M
169 56 M
178 60 M
173 55 M
183 73 M
170 62 M
169 73 M
183 60 M
162 56.5 M
178 68 M
178 65 M
168 56 M
173 56 M
179 63 M
179 80 M
170 75 M
172 69 M
175 70 M
178 65 M
179 74 M
171 75 M
180 60 M
175 60 M
170 58 M
185 68.5 M
175 64 M
173 60 M
172 70 M
177 65 M
182 72 M
172 70 M
177 58 M
175 60 M
175 68 M
173 63 M];
% 1.parzen窗法()
h=0.5*sqrt(50);
v=h/sqrt(50);
sum1=0;
sum2=0;
g=zeros(1,300);
for j=1:300
for i=1:50
sum1=sum1+exp(-0.5*((t(j,1)-a(i,1))/v)^2);
sum2=sum2+exp(-0.5*((t(j,1)-b(i,1))/v)^2);
end
if sum1>(sum2*5)
g(1,j)=1;
elseif sum1<(sum2*5)
g(1,j)=2;
elseif sum1==(sum2*5)
g(1,j)=0;
end
end
s1=0;s2=0;
for i=1:50
if g(1,i)~=1;
s1=s1+1;
end
end
s1;
for j=51:300
if g(1,j)~=2;
s2=s2+1;
end
end
s2;
% 2.Fiher线性判别法
x1=sum(a)/50;
x2=sum(b)/50;
ss1=zeros(2,2);ss2=zeros(2,2);
for i=1:50
ss1=ss1+(a(i,:)-x1)'*(a(i,:)-x1);
ss2=ss2+(b(i,:)-x2)'*(a(i,:)-x2);
end
sss=ss1+ss2;w=zeros(2,1);
w=inv(sss)*(x1-x2)';
y1=w'*x1';
y2=w'*x2';
w0=(y1+y2)/2;
sh1=zeros(1,50);sh2=zeros(1,50);
for i=1:50
if w'*a(i,:)'>w0
sh1(i)=1;
end
if w'*a(i,:)'
end
if w'*a(i,:)'==w0
sh1(i)=0;
end
end
for i=1:50
if w'*b(i,:)'>w0
sh2(i)=1;
elseif w'*b(i,:)'
else
sh2(i)=0;
end
end
u1=0;u2=0;
for i=1:50
if sh1(i)~=1
u1=u1+1;
end
if sh2(i)~=2
u2=u2+1;
end
end
u1;
u2;
%测试样本
x3=sum(t(1:50,1:2))/50;
x4=sum(t(51:300,1:2))/250;
sss1=zeros(2,2);sss2=zeros(2,2);
for i=1:50
sss1=sss1+(t(i,1:2)-x3)'*(t(i,1:2)-x3);
end
for i=51:300
sss2=sss2+(t(i,1:2)-x4)'*(t(i,1:2)-x4);
end
ssss=sss1+sss2;ww=zeros(2,1);
ww=inv(ssss)*(x3-x4)';
y3=ww'*x3';
y4=ww'*x4';
ww0=(y3+y4)/2;
sh3=zeros(1,300);
for i=1:50
if ww'*t(i,1:2)'>ww0
sh3(i)=1;
elseif ww'*t(i,1:2)'
else
sh3(i)=0;
end
end
for i=51:300
if ww'*t(i,1:2)'>ww0
sh3(i)=1;
elseif ww'*t(i,1:2)'
else
sh3(i)=0;
end
end
u3=0;u4=0;
for i=1:50
if sh3(i)~=1
u3=u3+1;
end
end
for i=51:300
if sh3(i)~=2
u4=u4+1;
end
end
u3;
u4;
%留一法(parzen窗法)
h1=0.5*sqrt(50);
v1=h1/sqrt(49);
h2=0.5*sqrt(50);
v2=h2/sqrt(50);
su1=0;
su2=0;
su3=0;
su4=0;
su5=0;
su6=0;
su7=0;
su8=0;
g1=zeros(1,50);g2=zeros(1,50);
for j=1:50
for i=1:50
su1=su1+exp(-0.5*((a(j,1)-a(i,1))/v1)^2);
su2=su2+exp(-0.5*((a(j,1)-b(i,1))/v2)^2);
end
su1=(su1-1)/sqrt(49);
su2=su2/sqrt(50);
if su1>(su2*50/49)
g1(1,j)=1;
elseif su1<(su2*50/49)
g1(1,j)=2;
elseif su1==(su2*50/49)
g1(1,j)=0;
end
end
for j=1:50
for i=1:50
su3=su1+exp(-0.5*((b(j,1)-a(i,1))/v2)^2);
su4=su4+exp(-0.5*((b(j,1)-b(i,1))/v1)^2);
end
su3=su3/sqrt(50);
su4=(su4-1)/sqrt(49);
if su3>(su4*49/50)
g2(1,j)=1;
elseif su3<(su4*49/50)
g2(1,j)=2;
elseif su3==(su4*49/50)
g2(1,j)=0;
end
end
ss1=0;ss2=0;
for i=1:50
if g1(1,i)~=1;
ss1=ss1+1;
end
end
ss1
for j=1:50
if g2(1,j)~=2;
ss2=ss2+1;
end
end
ss2参考资料:张绍武
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯