0
点赞
收藏
分享

微信扫一扫

工作中用到的数通、安全的查询、工具、文档链接

读思意行 2023-12-15 阅读 37

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

🌳 c-Decision-tree

Introduction 🙌

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

三步实现

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

#define feature 4 //改成需要的特征数量

1️⃣ 🤔 想好特征名,line18

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

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

string test[] = {"晴", "温", "中", "是"};

交互(可选)

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

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;
}
举报

相关推荐

0 条评论