Online · Zagreb · Croatia

Online Robotics Classes for Kids in Zagreb

Online robotics classes for kids in Zagreb serve local and expat families with clear English instruction and the optional 100-Mission Hero Journey for structured progression from Explorer to Tech Champion.

Online robotics Zagreb

Chapter 108 – Build a Decision Tree Model with Python and Scikit-Learn

1. End-to-End Project Workflow

This project loads the Iris dataset, applies pre-pruning, trains a DecisionTreeClassifier, visualizes the tree, and evaluates with Accuracy, Confusion Matrix, Precision, Recall, and F1-Score.

  • Data ingestion (Iris features and labels)
  • Stratified 70/30 train–test split
  • Pre-pruned model: max_depth=3, criterion='entropy'
  • Tree visualization and traversal
  • Evaluation: ~93.3% accuracy, 3×3 confusion matrix, class metrics

2. Dataset and Stratified Split

Iris features: petal/sepal length and width. Classes: Setosa, Versicolor, Virginica.

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, stratify=y, random_state=42
)

stratify=y keeps the same class proportions in train and test (e.g. 35 per class in train, 15 per class in test), avoiding imbalance skew.

3. Model Construction and Pre-Pruning

from sklearn.tree import DecisionTreeClassifier

clf = DecisionTreeClassifier(
    max_depth=3,
    criterion='entropy',
    random_state=42
)
clf.fit(X_train, y_train)
  • max_depth=3 — limits depth to reduce overfitting
  • criterion='entropy' — splits by Information Gain
  • random_state=42 — reproducible results

4. Interpreting the Tree

Root: Petal Length ≤ 2.45? (Entropy ≈ 1.585, 105 samples).

  • True → pure Setosa leaf (35 samples, Entropy 0)
  • False → Petal Width ≤ 1.75 on remaining 70 samples, then further splits on petal/sepal length into four leaves (e.g. pure Versicolor, pure Virginica, and a mixed leaf that votes majority)

5–6. Evaluation and Confusion Matrix

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

y_pred = clf.predict(X_test)
print(accuracy_score(y_test, y_pred))  # ~0.933 (93.3%)
print(confusion_matrix(y_test, y_pred))

Typical 3×3 pattern on 45 test samples: Setosa 15/15 correct; Virginica 15/15 correct; Versicolor 12/15 correct with 3 misclassified as Virginica. The entire ~6.7% error comes from Versicolor ↔ Virginica confusion.

7. Classification Report Metrics

Class Precision Recall F1-Score Support
Setosa1.001.001.0015
Versicolor1.000.800.8915
Virginica0.831.000.9115
Overall——0.9345
  • Precision — of predicted positives, how many were correct
  • Recall — of actual positives, how many were found
  • F1 — harmonic mean of precision and recall
  • Support — true sample count per class

8. Complete Script Outline

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier, plot_tree
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
import matplotlib.pyplot as plt

iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.3, stratify=y, random_state=42
)
clf = DecisionTreeClassifier(max_depth=3, criterion='entropy', random_state=42)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
print(accuracy_score(y_test, y_pred))
print(confusion_matrix(y_test, y_pred))
print(classification_report(y_test, y_pred, target_names=iris.target_names))
plt.figure(figsize=(12, 8))
plot_tree(clf, feature_names=iris.feature_names, class_names=iris.target_names, filled=True)
plt.show()

Lesson Q&A

It keeps the same class proportions in train and test. On Iris, each class gets equal share (e.g. 15 test samples each), so evaluation is not skewed by imbalance.

max_depth=3 limits vertical growth; criterion='entropy' uses Information Gain. The tree stayed shallow (about four leaves) with ~93.3% test accuracy and remained readable.

Setosa and Virginica were perfect (15/15). Versicolor was 12/15 correct; 3 were labeled Virginica. All of the ~6.7% error came from that confusion—suggesting more distinguishing features between those two species could help.

What children can learn

WhatsApp +92 322 421 7059

AI and Robotics Club | The 100 Mission AI & Robotics Hero Journey

Recommended self-paced course for parents & educators

mBlock Coding for Kids on Udemy.

Disclosure: This page contains affiliate links. We may earn from qualifying purchases at no extra cost to you. Links are intended for parents and educators, not as marketing directed at young children.

Capital Tech Coders: Interactive Robotics and Control Systems in Zagreb

Zagreb’s international community often seeks English STEM options online. Classes cover the sense → decide → act loop without inventing a capital campus. The 100-Mission pathway offers structured levels for motivated learners. Sensor processing, control systems and systematic testing form the core. Enquire WhatsApp +92 322 4217059. No fabricated local labs or career guarantees.

Frequently asked questions

Are classes in Zagreb delivered in English?

Yes, classes are taught in English, serving local and expat families in Zagreb.

What roadmap guides student learning progression?

Students follow our 100-Mission Hero Journey, advancing step-by-step from Explorers to Tech Champions.

How can parents in Zagreb contact us on WhatsApp?

Message our support team directly on WhatsApp at +92 322 4217059.

Explore related learning

SplitPython · Split RijekaSTEM · Rijeka SofiaRobotics · Sofia