一個數據結構期末作業(有興趣用的話可以高抬貴手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;
}