开箱即用的C++决策树简单实现

一个数据结构期末作业(有兴趣用的话可以高抬贵手star下⭐~)GitHub - mcxiaoxiao/c-Decision-tree: 决策树c++简单实现 🌳 c-Decision-tree 附大作业/课设参考文档.doc

🌳 c-Decision-tree

Introduction 🙌

c-Decision-tree 🌳 简单的决策树 比较严谨的c++实现,如果输出有报错可能是不支持emoji 代码以天气预测是否适合出行为例,修改起来很方便

三步实现

0️⃣ 🤔 想好想要多少个特征,line13:

cpp 复制代码
#define feature 4 //改成需要的特征数量

1️⃣ 🤔 想好特征名,line18

cpp 复制代码
//四个特征的名称,比如天气取值有三个:晴,阴,雨 
string attribute[] = {"天气", "温度", "湿度", "是否有风"};

3️⃣ 🖊 修改data.txt中的案例数据,修改测试数据line255

cpp 复制代码
string test[] = {"晴", "温", "中", "是"};

交互(可选)

去掉以下注释,修改成自己修改后逻辑下的交互提示,line256

cpp 复制代码
int main() {	
	createDataset();
	root = createTree(root, X, attributes);
	print(root, 0);
	string test[] = {"晴", "温", "中", "是"};
    // //自助交互
    // cout << "👋  请输入天气情况 ☁️ (晴/阴/雨)";
    // cin >> test[0];
    // cout << "😴  请输入温度 🌡️ (热/温/凉爽)";
    // cin >> test[1];
    // cout << "🌁  请输入湿度 💦 (高/中)";
    // cin >> test[2];
    // cout << "🚗  请输入是否刮风 🌬 (是/否)";
    // cin >> test[3];
	int i;
	cout << endl << "属性:";
	for(i=0; i<feature; i++)
		cout << attributes[i] << "\t";
	cout << endl << "输入:";
	for(i=0; i<feature; i++)
		cout << test[i] << "\t";
	cout << endl << "预测:";
	cout << classify(root, attributes, test) +"出行" << endl;
	freeNode(root);
	return 0;
}
相关推荐
2401_892070987 小时前
【Linux C++ 日志系统实战】LogFile 日志文件管理核心:滚动策略、线程安全与方法全解析
linux·c++·日志系统·日志滚动
yuzhuanhei7 小时前
Visual Studio 配置C++opencv
c++·学习·visual studio
Wenweno0o7 小时前
0基础Go语言Eino框架智能体实战-chatModel
开发语言·后端·golang
chenjingming6667 小时前
jmeter线程组设置以及串行和并行设置
java·开发语言·jmeter
cch89187 小时前
Python主流框架全解析
开发语言·python
不爱吃炸鸡柳7 小时前
C++ STL list 超详细解析:从接口使用到模拟实现
开发语言·c++·list
十五年专注C++开发7 小时前
RTTR: 一款MIT 协议开源的 C++ 运行时反射库
开发语言·c++·反射
Momentary_SixthSense7 小时前
设计模式之工厂模式
java·开发语言·设计模式
‎ദ്ദിᵔ.˛.ᵔ₎8 小时前
STL 栈 队列
开发语言·c++
勿忘,瞬间8 小时前
数据结构—顺序表
java·开发语言