from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score # Step 1: Load the Iris dataset X, y = load_iris(return_X_y=True) # Step 2: Split data into training (80%) and testing (20%) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Step 3: Initialize Decision Tree Classifier clf = DecisionTreeClassifier(random_state=42) # Step 4: Train the model clf.fit(X_train, y_train) # Step 5: Predict and evaluate y_pred = clf.predict(X_test) acc = accuracy_score(y_test, y_pred) * 100 print(f"Decision Tree model accuracy: {acc:.2f}%") __ __