开箱即用的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;
}
相关推荐
QX_hao4 小时前
【Go】--反射(reflect)的使用
开发语言·后端·golang
inferno4 小时前
Maven基础(二)
java·开发语言·maven
我是李武涯4 小时前
从`std::mutex`到`std::lock_guard`与`std::unique_lock`的演进之路
开发语言·c++
卡提西亚5 小时前
C++笔记-10-循环语句
c++·笔记·算法
史不了6 小时前
静态交叉编译rust程序
开发语言·后端·rust
亮剑20186 小时前
第1节:C语言初体验——环境、结构与基本数据类型
c++
读研的武6 小时前
DashGo零基础入门 纯Python的管理系统搭建
开发语言·python
William_wL_6 小时前
【C++】类和对象(下)
c++
Andy6 小时前
Python基础语法4
开发语言·python