📄 dtree.h
字号:
#ifndef _DTREE_H_
#define _DTREE_H_
#include <string>
#include <vector>
#include <set>
#include <ctime>
#include <algorithm>
#include <cmath>
using namespace std;
int trainAllNum = 500; //所有训练数据的范围
int testAllNum = 190; //所有测试数据的范围
const int MaxAttr = 15; //属性的个数
const int ArrtNum[MaxAttr] = {2, 2, 2, 4, 3, 14, 9, 2, 2, 2, 2, 2, 3, 2, 2}; //每种属性对应的取值个数
struct OriganData
{
char A1;
double A2;
double A3;
char A4;
string A5;
string A6;
string A7;
double A8;
char A9;
char A10;
double A11;
char A12;
char A13;
double A14;
double A15;
char label;
};
struct StoreData
{
int A[15];
char label;
};
struct TNode
{
int attrNum; //选取的是哪个属性
int attr; //属性的取值
char label; //例子的正负
};
struct DTree
{
TNode node;
vector<DTree*> childs;
};
void init();
int creatTree(DTree*& p, const vector<StoreData> &examples, vector<int> &attributes);
void readData(vector<OriganData> &data, const char* fileName);
void selectData(vector<OriganData> &data, vector<OriganData> &subdata, unsigned int selectDataNum, int dataNum);
void processConValue();
bool header(const OriganData &d1, const OriganData &d2);
double Gain(double p1, double s1, double p2, double s2);
bool allTheSame(const vector<StoreData> &samples, char);
char mostCommonAttr(const vector<StoreData> &samples);
int findBestArrt(const vector<StoreData> &examples, vector<int> &attributes);
void changeData(vector<OriganData> &Otrain, vector<StoreData> &train);
void testData();
char testTree(DTree *p, StoreData d);
void printTree(DTree *p, int depth);
#endif //_DTREE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -