资源简介
里面的数据来自UCI库,机器学习C4.5算法完全采用C语言实现
代码片段和文件信息
/****************************
DATA: Car Evaluation Database(from UCI)
决策树学习算法C实现(彭杰)
Copyright 2015/3/21 owner by pengjie
All rights reserved
*******************************/
#include “main.h“
const int dataline = 1728;
const int attrinum = 7;
const int maxTree = 1000;
void SetMapAttr( StringCharMap *mapAttr );
int main()
{
DesTreePoint *tree = new DesTreePoint[maxTree];
//pre-input
char *file = “C:\\Users\\Administrator\\Desktop\\machine_data\\car.data“;
int attriSome[attrinum] = {4443334};
StringCharMap mapAttr[attrinum];
SetMapAttr( mapAttr );
int train = 1650; //the number of train data
char **data = new char*[dataline];
for(int i=0;i data[i] = new char[attrinum];
if( -1!=ReadData(dataattriSomemapAttrfiledatalineattrinum) )
{
CreateDecisionTree( treetrain attrinum dataattriSome );
}
int correct = 0;
int sum = 0;
for(int i=(train+1);i {
++sum;
bool eva = predict(treedata[i]attrinum);
if(eva)
++correct;
}
double rp = double(correct)/sum;
printf(“the right correction: %f\n“rp);
for(int i=0;i delete []data[i];
delete []data;
delete []tree;
return 0;
}
void SetMapAttr( StringCharMap *mapAttr )
{
mapAttr[0][“vhigh“] = ‘0‘;
mapAttr[0][“high“] = ‘1‘;
mapAttr[0][“med“] = ‘2‘;
mapAttr[0][“low“] = ‘3‘;
mapAttr[1][“vhigh“] = ‘0‘;
mapAttr[1][“high“] = ‘1‘;
mapAttr[1][“med“] = ‘2‘;
mapAttr[1][“low“] = ‘3‘;
mapAttr[2][“2“] = ‘0‘;
mapAttr[2][“3“] = ‘1‘;
mapAttr[2][“4“] = ‘2‘;
mapAttr[2][“5more“] = ‘3‘;
mapAttr[3][“2“] = ‘0‘;
mapAttr[3][“4“] = ‘1‘;
mapAttr[3][“more“] = ‘2‘;
mapAttr[4][“small“] = ‘0‘;
mapAttr[4][“med“] = ‘1‘;
mapAttr[4][“big“] = ‘2‘;
mapAttr[5][“low“] = ‘0‘;
mapAttr[5][“med“] = ‘1‘;
mapAttr[5][“high“] = ‘2‘;
mapAttr[6][“unacc“] = ‘0‘;
mapAttr[6][“acc“] = ‘1‘;
mapAttr[6][“good“] = ‘2‘;
mapAttr[6][“vgood“] = ‘3‘;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 51867 2015-03-04 21:57 machine_learnning\car.data
文件 3097 2015-03-03 19:39 machine_learnning\car.names
文件 2030 2015-03-21 15:26 machine_learnning\main.cpp
文件 9736 2015-03-21 15:24 machine_learnning\main.h
目录 0 2015-03-21 15:47 machine_learnning
----------- --------- ---------- ----- ----
66730 5
- 上一篇:最小生成树MFC
- 下一篇:Logistic回归C语言实现
相关资源
- 目标检测 机器学习方法 静态场景 测
- 机器学习-数据挖掘-梯度下降算法C+
- 简单的梯度下降C++实现
- 机器学习分类算法实现c++语言和c语版
- C语言设计模式
- 编译好的c++机器学习库shark4.0
- haar分类器人脸检测MFC实现
- Matlab实现Mnist-image 手写数字图像识别
- 机器学习中决策树ID3算法 理论分析与
- Maxent 模型代码
- C++实现回归算法(逻辑回归 线性回归
- 线性回归c++实现
- C++实现朴素贝叶斯分类器
- Em算法实现聚类(VC++实现)
- 利用组合惯导实现多帧点云拼接并迭
- C++实现K最邻近算法(机器学习 KNN K
- 机器学习贝叶斯学习器——关于是否
- knn分类器c++实现含测试数据IRIS
- 贝叶斯分类器c++源代码含测试数据
- OpenCV机器学习SVM支持向量机的分类程
评论
共有 条评论