Practical - 4 4.2 Decision Tree Implementation
Practical - 4 4.2 Decision Tree Implementation
Practical – 4
4.2 Decision Tree Implementation
A Decision Tree is a supervised learning algorithm used for both classification and regression tasks. It
works by splitting the dataset into branches based on feature values, leading to a tree-like structure where
each internal node represents a decision rule, and each leaf node represents an outcome.
# Make Predictions
y_pred = clf.predict(X_test)
# Print Accuracy
print("Accuracy:", accuracy_score(y_test, y_pred))
plt.figure(figsize=(10, 6))
plot_tree(clf, feature_names=iris.feature_names[:2], class_names=iris.target_names, filled=True)
plt.title("Decision Tree Visualization on Iris Dataset")
plt.show()
Output: