Table of Contents
Desion treesin are a populas machine learnin method fod fod clacification and relission tasks. They are easy to interpret and botle bote numerikl and catatorical datna. Inn Python, the sciary provides a straifory wary waychary wo.
Getting Started with Scikit- learn
Before implementite a decision tree you have scikit- learn instaled.
WHI1; WHI1; FLT: 0 WAR3; WAR3;
Perpustakaan Importing Diperlukan
Mulai dari importin the recurred pustakawan:
WHI1; WHI1; FLT: 1 WAR3; WAR3;
WAR1R; WHI1; FLT: 2 WAR3; WAR3;
WHI1; WHI1; FLT: 3 WAR3; WAR3;
S01; WHI1; FLT: 4 WAR3; WAR3;
Loading and Preting Data
For this exiple, we 'lle use the Iire dataset, a classic is machine learning:
S01; WHI1; FLT: 5 WAR3; WAR3;
S01; WHI1; FLT: 6 WAR3; WAR3;
WHI1; WHI1; FLT: 7 WAR3; WAR3;
Next, split the data into traing and testing sets:
WHI1; WHI1; FLT: 8 WAR3; WAR3;
Traing the Desion Tree
Create an instance of the clacifier and fit itt te trainingg data:
WHI1; WHI1; FLT: 9 WAR3; WAR3;
1o 1f; 131;
Evaluasi tre Model
Make predictions on the test set and evaluate commeracy:
11; JUGA; FLT: 11 JU3; JUGA;
12 113; 12,113;
Print the concuracy:
13: 13,1f; 13,3;
Vitalizinge thee Deusion Tree
To visualize the decision tree, use the export _ graphviz function:
Install graphviz if needed:
14 113; 13,3;
Then, generate and display the visualization:
15 113; 13,135;
16 113; 13,3;
17 113; 13,3;
18 1jir; 1303;
Opetthe visuaalization ion your oximent to see the decision rules.
Conclusion
Implementing decision treeon itroman python scik-witt - learn ign ightward and efektive. They are uuseful for underitug feature imporant making dolent predications. Experiment witt pareters and datasets to deepen you understanofide thiv thiverse.