www.pudn.com > MyDM1.rar > ID3.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace MyDM1
{
///
/// ID3 的摘要说明。
///
public class ID3
{
public ID3(){DT=new DecisionTree();}
public DecisionTree DT;
public DecisionTree MakeDTree(DataSet ds)
{
int count=ds.Tables[0].Rows.Count;
int col=ds.Tables[0].Columns.Count;
return DT;
}
public double Mutual_Information( DataSet ds , int attribute_number)//输入属性列号,返回该属性的互信息
{
MyDM1.Database db=new Database();
string[] attribute_count=new string[20];
MyDM1.List attribute_value=new MyDM1.List();
MyDM1.List distinct_attribute=new MyDM1.List();
double count=ds.Tables[0].Rows.Count;//训练集的数据条数
double[] attribute=new double[10]; //属性数组:attribute_1[0]表示属性1取第一个值的个数(天气取值为"晴"的个数)
double[] result=new double[10]; //属性类别数组:result[0]表示该条数据的类别取"P"值的个数
double[] P_1=new double[10]; //该属性概率数组:P_1[0]表示属性1取第一个值的概率
double[,] P1=new double[10,10]; //该属性概率数组:P1[0,0]表示属性1取第一个值同时类别取值为第一个值的概率,P_1_1[1]表示属性1取第一个值同时类别取值为第二个值的概率
double condition_entropy=0; //条件熵
double information_entropy=0; //信息熵
int i=0,j=0;
for(i=0;i