The document outlines a Python implementation of a Decision Tree Classifier using the Iris dataset. It includes steps for loading the dataset, splitting it into training and testing sets, training the classifier, making predictions, and calculating accuracy. Additionally, it provides a visualization of the trained decision tree.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
0 views
Decision Tree
The document outlines a Python implementation of a Decision Tree Classifier using the Iris dataset. It includes steps for loading the dataset, splitting it into training and testing sets, training the classifier, making predictions, and calculating accuracy. Additionally, it provides a visualization of the trained decision tree.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Decision Tree:
# Import necessary libraries
from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier, plot_tree from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import matplotlib.pyplot as plt
# Load the Iris dataset
iris = load_iris() X = iris.data # Features (sepal and petal lengths & widths) y = iris.target # Target labels (setosa, versicolor, virginica)
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.3, random_state=42)