refactor: rename folder structure to sort for algorithms

This commit is contained in:
2026-04-30 18:59:56 +02:00
parent 9a8d59290b
commit dbc2b765a7
13 changed files with 124 additions and 54 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

@@ -0,0 +1,42 @@
"""
Use a decisiontree classifier to predict flowers based on sepal and petal features
- This is an example of a supervised ML algorithm
- it has labels on the training data
- you tell the model: this is class X during training
"""
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
# load the iris data set and look at its dimensions
iris = datasets.load_iris()
print(iris.data.size)
print(iris.target.size)
print(iris.feature_names)
print(iris.target_names)
# use a decition tree classifier
classifier = DecisionTreeClassifier()
# use all but the last sample for training
classifier.fit(iris.data[:-1], iris.target[:-1])
# use the model to predict the last data sample
last_sample = iris.data[-1:]
last_target = iris.target[-1:]
print(f"predicted: {last_sample} vs real: {last_target}")
# print the tree for visual inspection
fig, ax = plt.subplots(figsize=(20, 10))
tree.plot_tree(
classifier,
feature_names=iris.feature_names,
class_names=iris.target_names,
filled=True,
rounded=True,
ax=ax,
)
fig.savefig("decisiontree_iris.png", dpi=150, bbox_inches="tight")