image_output_1.png
from sklearn.datasets import load_iris

from sklearn.tree import DecisionTreeClassifier, plot_tree

from sklearn.tree import DecisionTreeClassifier, plot_tree

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd

data = pd.read_csv('/kaggle/input/drugs-a-b-c-x-y-for-decision-trees/drug200.csv')

gini_classifier = DecisionTreeClassifier(criterion='gini')

gini_classifier.fit(X_train, y_train)

y_pred = gini_classifier.predict(X_test)

features = list(X_train.columns)
target = list(y_train.unique())

fig, ax = plt.subplots(figsize=(12, 8))
plot_tree(gini_classifier, filled=True, feature_names=features, class_names=target, ax=ax)
plt.show()

import pandas as pd
iris = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None)
iris.columns = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'class']
class_counts = iris['class'].value_counts()
class_proportions = class_counts / len(iris)

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier, plot_tree
import matplotlib.pyplot as plt

# Load the iris dataset
iris = load_iris()

# Train a decision tree classifier
clf = DecisionTreeClassifier()
clf.fit(iris.data, iris.target)

# Visualize the decision tree using Matplotlib
fig, ax = plt.subplots(figsize=(12, 8))
plot_tree(clf, filled=True, feature_names=iris.feature_names, class_names=iris.target_names, ax=ax)
plt.show()

iris = load_iris()
iris.target