⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 模式识别_贝叶斯分类器
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.button2.Text = "身高体重相关";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button5
			// 
			this.button5.Location = new System.Drawing.Point(13, 134);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(74, 21);
			this.button5.TabIndex = 1;
			this.button5.Text = "导入测试样本";
			this.button5.Click += new System.EventHandler(this.button5_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(400, 414);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.statusBar1);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid3)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			dt1=new DataSet();
			try{
				dt1.ReadXml("FEMALE.xml");
				dataGrid1.SetDataBinding(dt1,"female");
				statusBar1.Text="女生样本人数:"+dt1.Tables[0].Rows.Count;
				button1.Enabled=false;
			}catch(Exception ee)
			{
				MessageBox.Show(ee.Message);
			}

			
			//MessageBox.Show((String)ds.Tables[0].Rows[0]["height"]);
		}

		private void button4_Click(object sender, System.EventArgs e)
		{
			dt2=new DataSet();
			try
			{
				dt2.ReadXml("MALE.xml");
				dataGrid2.SetDataBinding(dt2,"male");
				statusBar1.Text+="  男生样本人数:"+dt2.Tables[0].Rows.Count;
				button4.Enabled=false;
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.Message);
			}
		}

		private void button5_Click(object sender, System.EventArgs e)
		{
			openFileDialog1.ShowDialog();
			String fname=openFileDialog1.FileName;
			dt3=new DataSet();
			try
			{
				String temp=DateTime.Now.ToFileTime()+".xml";
				FileInfo myFile=new FileInfo(fname);
				f=myFile.CopyTo(temp);
				f.Attributes=FileAttributes.Hidden;
				dt3.ReadXml(temp);
				dataGrid3.SetDataBinding(dt3,"person");
				statusBar1.Text+="  测试样本人数:"+dt3.Tables[0].Rows.Count;
				button5.Enabled=false;
				
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.Message);
			}
		}

		private void button2_Click(object sender, System.EventArgs e)//weight+height
		{
			PRAlgClass pr=new PRAlgClass(dt1,dt2);
			float count=0;
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				double[] t=new double[2];
				t[0]=double.Parse((String)dt3.Tables[0].Rows[i]["height"]);
				t[1]=double.Parse((String)dt3.Tables[0].Rows[i]["weight"]);
				if(pr.IsMale(t,n))
				{
					dt3.Tables[0].Rows[i]["分类结果"]="m";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}
				else 
				{
					dt3.Tables[0].Rows[i]["分类结果"]="f";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}			
			}
			count=count*100/dt3.Tables[0].Rows.Count;
			label1.Text="识别率:"+count.ToString()+"%";
		}

		private void button3_Click(object sender, System.EventArgs e)//height
		{
			PRAlgClass pr=new PRAlgClass(dt1,dt2);
			float count=0;
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				double[] t=new double[2];
				t[0]=double.Parse((String)dt3.Tables[0].Rows[i]["height"]);
				t[1]=double.Parse((String)dt3.Tables[0].Rows[i]["weight"]);
				if(pr.IsMale(t,0,n))
				{
					dt3.Tables[0].Rows[i]["分类结果"]="m";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}
				else 
				{
					dt3.Tables[0].Rows[i]["分类结果"]="f";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}			
			}
			count=count*100/dt3.Tables[0].Rows.Count;
			label1.Text="识别率:"+count.ToString()+"%";
		}

		private void button7_Click(object sender, System.EventArgs e)
		{
			/*
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				dt3.Tables[0].Rows[i]["分类结果"]="?";
				dt3.Tables[0].Rows[i]["正确性"]="?";
			}
			*/
			label1.Text="";
			button5.Enabled=true;
			dt3.Clear();
		}

		private void button6_Click(object sender, System.EventArgs e)//weight
		{
			PRAlgClass pr=new PRAlgClass(dt1,dt2);
			float count=0;
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				double[] t=new double[2];
				t[0]=double.Parse((String)dt3.Tables[0].Rows[i]["height"]);
				t[1]=double.Parse((String)dt3.Tables[0].Rows[i]["weight"]);
				if(pr.IsMale(t,1,n))
				{
					dt3.Tables[0].Rows[i]["分类结果"]="m";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}
				else 
				{
					dt3.Tables[0].Rows[i]["分类结果"]="f";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}			
			}
			count=count*100/dt3.Tables[0].Rows.Count;
			label1.Text="识别率:"+count.ToString()+"%";
		}

		private void button8_Click(object sender, System.EventArgs e)//wh
		{
			PRAlgClass pr=new PRAlgClass(dt1,dt2);
			float count=0;
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				double[] t=new double[2];
				t[0]=double.Parse((String)dt3.Tables[0].Rows[i]["height"]);
				t[1]=double.Parse((String)dt3.Tables[0].Rows[i]["weight"]);
				if(pr.IsMale2(t,n))
				{
					dt3.Tables[0].Rows[i]["分类结果"]="m";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}
				else 
				{
					dt3.Tables[0].Rows[i]["分类结果"]="f";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}			
			}
			count=count*100/dt3.Tables[0].Rows.Count;
			label1.Text="识别率:"+count.ToString()+"%";
		}

		private void button9_Click(object sender, System.EventArgs e)
		{
			PRAlgClass pr=new PRAlgClass(dt1,dt2);
			float count=0;
			for(int i=0;i<dt3.Tables[0].Rows.Count;i++)
			{
				double[] t=new double[2];
				t[0]=double.Parse((String)dt3.Tables[0].Rows[i]["height"]);
				t[1]=double.Parse((String)dt3.Tables[0].Rows[i]["weight"]);
				if(pr.IsMale3(t,n))
				{
					dt3.Tables[0].Rows[i]["分类结果"]="m";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}
				else 
				{
					dt3.Tables[0].Rows[i]["分类结果"]="f";
					if((String) dt3.Tables[0].Rows[i]["分类结果"]==(String)dt3.Tables[0].Rows[i]["gent"]) 
					{
						dt3.Tables[0].Rows[i]["正确性"]="T";
						count++;
					}
					else dt3.Tables[0].Rows[i]["正确性"]="F";
				}			
			}
			count=count*100/dt3.Tables[0].Rows.Count;
			label1.Text="识别率:"+count.ToString()+"%";
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -