AAM 5th Practicle
AAM 5th Practicle
Write a python Programming code to implement decision tree for classification using suitable
data/dataset.
Classification Report:
accuracy 1.00 45
| |--- class: 0
| | | |--- class: 1
| | | |--- class: 2
| | | |--- class: 1
| | | |--- class: 2
Predicted class for sample data: setosa Explanation of Code
1. Dataset:
The Iris dataset contains four features ( sepal length, sepal width, petal
length, petal width) and three classes (Setosa, Versicolor, Virginica).
2. Data Splitting:
The dataset is divided into training (70%) and testing (30%) subsets.
3. Decision Tree Classifier:
criterion='gini': Specifies Gini impurity as the splitting criterion.
max_depth=3: Limits the depth of the tree to avoid overfitting.
4. Evaluation:
The model is evaluated using accuracy and a classification report.
5. Visualization:
plot_tree: Visualizes the tree structure.
export_text: Prints the textual rules of the decision tree.
6. Prediction:
Predicts the class of a new data sample based on learned patterns.