开箱即用的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;
}
相关推荐
biter down5 小时前
14:pytest-order 插件 顺序控制案例
开发语言·python·pytest
郝学胜-神的一滴5 小时前
Qt 高级开发 009: C++ Lambda 表达式
开发语言·c++·qt·软件构建
星栈独行6 小时前
我在 Rust 全栈项目里用 JWT 做无状态认证
开发语言·后端·rust·前端框架·开源·github·web
石山代码6 小时前
C++ 轻量级日志系统
开发语言·c++
小技与小术7 小时前
玩转Flask
开发语言·python·flask
SilentSamsara7 小时前
Python 性能优化:tracemalloc、profiling 与 C 扩展加速
开发语言·python·青少年编程·性能优化
冰小忆7 小时前
大驼峰命名规范和小驼峰命名规范的区别是什么?
开发语言·python
এ慕ོ冬℘゜8 小时前
JS 前端基础面试题
开发语言·前端·javascript
浩少7028 小时前
【无标题】
java·开发语言
nnsix9 小时前
C# 字符串 根据换行符分割
开发语言·c#