Emgu 决策树
MCvDTreeParams
cvFolds //If this parameter is >1, the tree is pruned using cv_folds-fold cross validation.
maxCategories //默认为10
maxDepth //This parameter specifies the maximum possible depth of the tree. That is the training algorithms attempts to split a node while its depth is less than max_depth. The actual depth may be smaller if the other termination criteria are met (see the outline of the training procedure in the beginning of the section), and/or if the tree is pruned.
minSampleCount //A node is not split if the number of samples directed to the node is less than the parameter value.
priors //错分类代价
regressionAccuracy //Another stop criteria - only for regression trees. As soon as the estimated node value differs from the node training samples responses by less than the parameter value, the node is not split further.
truncatePrunedTree //If true, the cut off nodes (with Tn<=CvDTree::pruned_tree_idx) are physically removed from the tree. Otherwise they are kept, and by decreasing CvDTree::pruned_tree_idx (e.g. setting it to -1) it is still possible to get the results from the original un-pruned (or pruned less aggressively) tree.
use1seRule //If true, the tree is truncated a bit more by the pruning procedure. That leads to compact, and more resistant to the training data noise, but a bit less accurate decision tree.
useSurrogates //If true, surrogate splits are built. Surrogate splits are needed to handle missing measurements and for variable importance estimation.
public bool Train(
Matrix<float> trainData, //A 32-bit floating-point, single-channel matrix,one vector per row
Emgu.CV.ML.MlEnum.DATA_LAYOUT_TYPE tflag, //data layout type: COL_SAMPLE or ROW_SAMPLE
Matrix<float> responses, //行阵等同于trainData,列数为1,表示训练数据的结果
Matrix<byte> varIdx,
//Can be null if not needed. When specified, identifies variables (features) of interest. It is a Matrix>int< of nx1
Matrix<byte> sampleIdx, //Can be null if not needed. When specified, identifies samples of interest. It is a Matrix>int< of nx1. 与上一个向量要么是基于0的整数列,要么是8位的标记,1预示有用,0预示跳过
Matrix<byte> varType, //The types of input variables. 是一个各个特征类型的基于0的标记(特征类型是CV_VAR_CATEGORICAL 还是 CV_VAR_ORDERED),它的长度是特征的个数加1,最后一个数字指定学习结果的类型
Matrix<byte> missingMask, //掩码矩阵,值为1表示相对应的值无效,值为0表示相对应的值有用
MCvDTreeParams param //The parameters for training the decision tree
)
示例程序:
private static DTree MushroomCreateDTree(Matrix<float> data, Matrix<byte> missing, Matrix<float> responses, int weight)
{
DTree dtree=new DTree();
Matrix<byte> varType=new Matrix<byte>(data.Width+1,1);
float[] priors = new float[] { 1, weight };
MCvDTreeParams mcd = new MCvDTreeParams();
mcd.maxDepth=8;
mcd.minSampleCount=10;
mcd.regressionAccuracy=0;
mcd.useSurrogates=true;
mcd.maxCategories=20;
mcd.cvFolds=10;
mcd.use1seRule=true;
mcd.truncatePrunedTree=true;
IntPtr p = Marshal.UnsafeAddrOfPinnedArrayElement(priors, 0); //将float[] 转化成 IntPtr类型
mcd.priors=p;
dtree.Train(data,Emgu.CV.ML.MlEnum.DATA_LAYOUT_TYPE.ROW_SAMPLE,responses,null,null,varType,missing,mcd);
dtree.Save(System.Environment.CurrentDirectory + "\\dtee.xml");
int varSuccess = 0;
for (int i = 0; i < data.Rows; i++)
{
Matrix<float> sample=new Matrix<float>(1,data.Width);
Matrix<byte> missingDataMask=new Matrix<byte>(1,missing.Width);
for (int j = 0; j < data.Width; j++)
{
sample[0, j] = data[i, j];
}
for (int j = 0; j < missing.Width; j++)
{
missingDataMask[0, j] = missing[i, j];
}
MCvDTreeNode mcn = dtree.Predict(sample, missingDataMask, false);
if (mcn.value == responses[i, 0])
varSuccess++;
}
Console.WriteLine(responses.Rows +": " + varSuccess);
return dtree;
}
Emgu 决策树的更多相关文章
- 使用python抓取婚恋网用户数据并用决策树生成自己择偶观
最近在看<机器学习实战>的时候萌生了一个想法,自己去网上爬一些数据按照书上的方法处理一下,不仅可以加深自己对书本的理解,顺便还可以在github拉拉人气.刚好在看决策树这一章,书里面的理论 ...
- 【Machine Learning】决策树案例:基于python的商品购买能力预测系统
决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...
- 决策树ID3算法的java实现(基本试用所有的ID3)
已知:流感训练数据集,预定义两个类别: 求:用ID3算法建立流感的属性描述决策树 流感训练数据集 No. 头痛 肌肉痛 体温 患流感 1 是(1) 是(1) 正常(0) 否(0) 2 是(1) 是(1 ...
- 决策树及R语言实现
决策树是什么 决策树是基于树结构来进行决策,这恰是人类在面临决策问题时一种很自然的处理机制.例如,我们要对"这是好瓜吗?"这样的问题进行决策时,通常会进行一系列的判断或" ...
- 决策树-ID3
id3:无法直接处理数值型数据,可以通过量化方法将数值型数据处理成标称型数据,但涉及太多特征划分,不建议 决策树:的最大优点在于可以给出数据的内在含义,数据形式非常容易理解: 决策树介绍:决策树分类器 ...
- python画决策树
1.安装graphviz.下载地址在:http://www.graphviz.org/.如果你是linux,可以用apt-get或者yum的方法安装.如果是windows,就在官网下载msi文件安装. ...
- MLlib决策树与集成树
决策树是一种常见的分类与回归机器学习算法,由于其模型表达性好,便于理解,并能取得较好的效果,而受到广泛的应用.下图是一个简单的决策树,决策树每个非叶子节点包含一个条件,对于具有连续值的特征,该条件为一 ...
- 决策树和基于决策树的集成方法(DT,RF,GBDT,XGBT)复习总结
摘要: 1.算法概述 2.算法推导 3.算法特性及优缺点 4.注意事项 5.实现和具体例子 内容: 1.算法概述 1.1 决策树(DT)是一种基本的分类和回归方法.在分类问题中它可以认为是if-the ...
- Spark中决策树源码分析
1.Example 使用Spark MLlib中决策树分类器API,训练出一个决策树模型,使用Python开发. """ Decision Tree Classifica ...
随机推荐
- 数据库查询Database中的表
public class UserDA { SqlConnection conn; SqlCommand cmd; public UserDA(Use uuu) { conn =new SqlConn ...
- Java数组课后作业
1.运行TestArrays.java,了解Arrays中的一些重要方法的用法. Arrays.equals(a 1, a2):判断数组是否相等. int[] b = Arrays.copyOf(a, ...
- css3 -- 背景图处理
1.多背景图片: p{ background-image:url() , url(); background-position:95% 90% , 50% 50%; background-repect ...
- Python基础6- 流程控制之if条件语句
Python条件语句是通过判断一条或多条条件语句的执行结果来决定执行哪条代码块的.Python 中if 语句用于控制程序的执行,基本形式为:if 判断条件: 执行语句……else: 执行语句…… #c ...
- HDU1402 A * B Problem Plus(FFT)
http://acm.hdu.edu.cn/showproblem.php?pid=1402 初学FFT. http://www.cnblogs.com/WABoss/p/FFT_Note.html ...
- 使用asynctask的问题
在使用asynctask 的onpostexcute 这个方法的时候,发现return 变量这个语句,只是return 到onpostexcute 本来 我是 private 变量1 方法1(){ ...
- ural 1075. Thread in a Space
1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dime ...
- Tomcat在局域网中localhost可以访问,但是无法通过本地ip访问,127.0.0.1也无法访问问题的解决方法
环境:Tomcat6,Windows Server2008 R2, Tomcat使用默认端口8080. 在BO服务器上使用Tomcat6作为WEB服务器,在服务器本地使用http://localhos ...
- Squid的简单使用
1. squid配置 # Squid normally listens to port http_port hosts_file /etc/hosts cache_access_log /var/lo ...
- Activiti工作流学习(二)流程实例、执行对象、任务
一.前言 前面说明了基本的流程部署.定义,启动流程实例等基本操作,下面我们继续来学习流程实例.执行对象.任务. 二.流程实例.执行对象说明 整个Activiti的生命周期经过了如下的几个步骤: 1.流 ...