0% found this document useful (0 votes)
16 views3 pages

Decision Tree - Ipynb - Colab

The document presents a classification task using the Iris dataset with a Decision Tree model. It includes data preparation, model training, and evaluation, showing high accuracy and performance metrics. The final classification report indicates excellent precision, recall, and f1-scores across all classes.

Uploaded by

Malak Aldwoah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Decision Tree - Ipynb - Colab

The document presents a classification task using the Iris dataset with a Decision Tree model. It includes data preparation, model training, and evaluation, showing high accuracy and performance metrics. The final classification report indicates excellent precision, recall, and f1-scores across all classes.

Uploaded by

Malak Aldwoah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Kelas (A)

Kelompok (A1)

Malak Khaled Ahmed Aldwoah 20220130235

Wan Muhammad Aulia Najmi 20220130162

Abdul waiz alqarnist 20220130121

Abriyanto 20220130208

toyib al habib panjaitan 20220130103

from sklearn.datasets import load_iris

X, y = load_iris(return_X_y=True)
print(f'Dimensi Feature:{X.shape}')
print(f'Class:{set(y)}')

Dimensi Feature:(150, 4)
Class:{0, 1, 2}

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

from sklearn.tree import DecisionTreeClassifier

tree_model = DecisionTreeClassifier(max_depth=4)

tree_model = tree_model.fit(X_train, y_train)

import matplotlib.pyplot as plt


from sklearn import tree
plt.rcParams['figure.dpi'] = 85
plt.subplots(figsize=(10, 10))
tree.plot_tree(tree_model, fontsize=10)
plt.show()
from sklearn.metrics import classification_report
y_pred = tree_model.predict(X_test)
print(classification_report(y_test, y_pred))

precision recall f1-score support

0 1.00 1.00 1.00 16


1 1.00 0.94 0.97 18
2 0.92 1.00 0.96 11

accuracy 0.98 45
macro avg 0.97 0.98 0.98 45
weighted avg 0.98 0.98 0.98 45

Start coding or generate with AI.

You might also like