本帖最后由 ゞ⑧鸢の翔 于 2014-9-3 15:50 编辑
最近在做一个决策树分类的编程,在获取表单,参考例程是以下实现。我想在数据库调用表单放在datatable里头,可是出来结果不一样,为什么呢?
[C#] 纯文本查看 复制代码 static DataTable getDataTable()
{
DataTable result = new DataTable("samples");
DataColumn column = result.Columns.Add("天气");
column.DataType = typeof(string);
column = result.Columns.Add("温度");
column.DataType = typeof(string);
column = result.Columns.Add("湿度");
column.DataType = typeof(string);
column = result.Columns.Add("风度");
column.DataType = typeof(string);
column = result.Columns.Add("结果");
column.DataType = typeof(string);
result.Rows.Add(new object[] { "晴天", "热", "高", "弱", "false" });
result.Rows.Add(new object[] { "晴天", "热", " 高", "强", "false" });
result.Rows.Add(new object[] { "多雨", "热", "高", "弱", "true" }); ...
return result;
}
想在数据库调出表单。
[C#] 纯文本查看 复制代码 DB db = new DB();
string str = "select * from Golf";
DataTable dt = db.reDt(str);
主程序中:
[C#] 纯文本查看 复制代码 DataTable samples = getDataTable();
int columnNum = samples.Columns.Count-1;
DecisionTreeID3 id3 = new DecisionTreeID3();
TreeNode root = id3.mountTree(samples, columnNum, attributes);
出来结果可行。也有分类。结果如下:
但是要是调用数据库的方式。
[C#] 纯文本查看 复制代码 DB db = new DB();
string str = "select * from Golf";
DataTable dt = db.reDt(str);
DataTable samples = dt;
int columnNum = samples.Columns.Count-1;
DecisionTreeID3 id3 = new DecisionTreeID3();
TreeNode root = id3.mountTree(samples, columnNum, attributes);
结果就只有一个true。
谢谢!怎样修改呢?谢谢老大!
|