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 ...
随机推荐
- 《DSP using MATLAB》示例Example4.10
上代码: b = [1, 0.4*sqrt(2)]; a = [1, -0.8*sqrt(2), 0.64]; % compute the polynomials coefficients given ...
- iOS10 UI教程视图的中心位置
iOS10 UI教程视图的中心位置 center表示的是视图的中心位置属性,这个属性在相对的UI层次结构上工作,和frame类似.center属性是一个在父视图上定义视图的位置的简便方法.center ...
- delphi 对Tmemo指定的行写入
mmoMonitor:Tmemo; mmoMonitor.Lines.ValueFromIndex[0]:=aInfo ; procedure TMainForm.LogInfo(aInfo: str ...
- https://www.nginx.com/blog/introduction-to-microservices/
https://www.nginx.com/blog/introduction-to-microservices/
- web开发的基础知识:http请求
引用自:http://blog.csdn.net/yefan2222/article/details/6198098 http://baike.baidu.com/view/1628025.htm?f ...
- JSP通过IP获取用户(客户端)的地理位置信息
<%!//获取客户端的IP public String getRemoteIP(HttpServletRequest request) { if (request.getHeader(" ...
- BZOJ3692 : 愚蠢的算法
两个函数相同等价于不存在长度为$3$的下降子序列. 先考虑随意填的部分,设$f[i][j]$表示考虑了$[i,n]$,下降子序列第$2$项的最小值的是这里面第$j$个的方案数,转移则考虑往序列里插数字 ...
- ajax、post、get实例
html代码: <!DOCTYPE HTML><html lang="en-US"><head> <meta charset=" ...
- BZOJ 1798 题解
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 5531 Solved: 1946[Submit ...
- 【BZOJ】3240: [Noi2013]矩阵游戏
题意 给出\(n, m(1 \le n, m \le 10^{1000000})\),求\(f(n, m) \ \mod \ 10^9+7\) $$\begin{cases}f(1, 1) = 1 \ ...