from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OrdinalEncoder
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris
from sklearn.tree import plot_tree
from sklearn.metrics import classification_report
# Load the iris dataset
iris = load_iris()
# Define the transformer
ct = ColumnTransformer(
[("encode", OrdinalEncoder(), [3])], remainder="passthrough"
)
# Transform the data
X = ct.fit_transform(iris.data)
# Define and fit the decision tree
tree = DecisionTreeClassifier()
tree.fit(X, iris.target)
# Visualize the tree
plot_tree(tree)
# Evaluate the tree on the training data
y_pred = tree.predict(X)
print(classification_report(iris.target, y_pred))