您好,欢迎访问三七文档
作业:在下列条件下,求待定样本x=(2,0)T的类别,画出分界线,编程上机。1、二类协方差相等,2、二类协方差不等。训练样本号k123123特征x1112-1-1-2特征x210-110-1类别ω1ω21、二类协方差不等Matlab程序如下:x1=[mean([1,1,2]),mean([1,0,-1])]',x2=[mean([-1,-1,-2]),mean([1,0,-1])]'x1=1.33330x2=-1.33330m=cov([1,1;1,0;2,-1]),n=cov([-1,1;-1,0;-2,-1])m=0.3333-0.5000-0.50001.0000n=0.33330.50000.50001.0000m1=inv(m),n1=inv(n)m1=12.00006.00006.00004.0000n1=12.0000-6.0000-6.00004.0000p=log((det(m))/(det(n)))p=0q=log(1)q=0x=[2,0]'x=20g=0.5*(x-x1)'*m1*(x-x1)-0.5*(x-x2)'*n1*(x-x2)+0.5*p-qg=-64(说明:g0,则判定x=[2,0]T属于ω1类)(化简矩阵多项式0.5*(x-x1)'*m1*(x-x1)-0.5*(x-x2)'*n1*(x-x2)+0.5*p-q,其中x1,x2已知,x设为x=[x1,x2]T,化简到(12x1-16+6x2)(x1-4/3)+(6x1-8+4x2)-(12x1+16-6x2)(x1+4/3)-(-6x1-8+4x2)x2,下面用matlab化简,程序如下)symsx2;symsx1;w=(12*x1-16+6*x2)*(x1-4/3)+(6*x1-8+4*x2)*x2-(12*x1+16-6*x2)*(x1+4/3)-(-6*x1-8+4*x2)*x2,simplify(w)w=(12*x1-16+6*x2)*(x1-4/3)+(6*x1-8+4*x2)*x2-(12*x1+16-6*x2)*(x1+4/3)-(-6*x1-8+4*x2)*x2ans=-64*x1+24*x2*x1(说明:则-64×x1+24×x2×x1=0,即x1=0,或者x2=8/3,很显然分界线方程为x1=0,因为x2=8/3连ω1类与ω2都分不开)2、二类协方差相等Matlab程序如下:l=m+nl=0.6667002.0000l1=inv(l)l1=1.5000000.5000g1=(x2-x1)'*m1*x+0.5*(x1'*l1*x1-x2'*l1*x2)-qg1=-64.0000(说明:g10,则判定x=[2,0]T属于ω1类)(x2-x1)'*m1ans=-32.0000-16.0000symsx11;symsx22;w1=-32*x11+(-16)*x22+0.5*(x1'*l1*x1-x2'*l1*x2)-q,simplify(w1)w1=-32*x11-16*x22ans=-32*x11-16*x22(说明:分界线方程为-32×x1-16×x2=0,即2×x1+x2=0)以下是matlab绘图程序:x1=[1;1;2];x2=[1;0;-1];plot(x1,x2,'mx','markersize',15);axis([-5,5,-5,5]);gridon;holdonx1=[-1;-1;-2];x2=[1;0;-1];plot(x1,x2,'m*','markersize',15);axis([-5,5,-5,5]);holdonx1=[2];x2=[0];plot(x1,x2,'mp','markersize',15);axis([-5,5,-5,5]);holdonx2=-5:0.02:5;x1=0;plot(x1,x2,'b');axis([-5,5,-5,5]);x1=-5:0.02:5;x2=-2*x1;plot(x1,x2,'-.k');axis([-5,5,-5,5]);绘图如下:-5-4-3-2-1012345-5-4-3-2-1012345(说明:×点为ω1类的样本点,*点位ω2类的样本点,五角星为待定样本,实直线为二类协方差不等时的分界线,点划线为二类协方差相等时的分界线。)
本文标题:贝叶斯分类作业题
链接地址:https://www.777doc.com/doc-4764419 .html