Online · Varna · Bulgaria

AI Courses for Kids in Varna

AI courses for kids in Varna introduce how computers learn from data through visual tools that show image and text recognition—on any standard home laptop with a browser.

AI Varna

Chapter 105 – Decision Trees Part 2: How Models Choose the Best Data Splits

1. Introduction: Translating Theory into Python Code

Previous topics covered Gini Impurity, Entropy, and Information Gain. This module implements a Decision Tree classifier in Scikit-Learn, inspects how features are ranked for splits, exports human-readable rules, and reads feature importances.

2. Environment Setup and Library Imports

  • numpy — array operations
  • DecisionTreeClassifier — core classifier from sklearn.tree
  • export_text — plain-text tree structure
  • make_classification — synthetic classification data
import numpy as np
from sklearn.tree import DecisionTreeClassifier, export_text
from sklearn.datasets import make_classification
print("Libraries loaded successfully!")

3. Synthetic Dataset Generation and Inspection

A small controlled set keeps the logic easy to visualize: 12 samples, 2 informative features, no redundant features, random_state=42 for reproducibility.

X, y = make_classification(
    n_samples=12,
    n_features=2,
    n_informative=2,
    n_redundant=0,
    random_state=42
)

for i in range(8):
    print(f"Sample {i+1}: Feature 1 = {X[i, 0]:.2f}, Feature 2 = {X[i, 1]:.2f} -> Class = {y[i]}")

Among the first 8 records, class mix is typically a few Class 0 and more Class 1 examples.

4. Model Training and Hyperparameter Tuning

  • max_depth=2 — limits depth to reduce overfitting
  • criterion='gini' — Gini Impurity for split quality (or 'entropy' for Information Gain)
  • random_state=42 — reproducible splits
tree = DecisionTreeClassifier(
    max_depth=2,
    criterion='gini',
    random_state=42
)
tree.fit(X, y)
print("Model training complete!")

5. Extracting Decision Rules & Explainable AI (XAI)

tree_rules = export_text(tree, feature_names=['feature_1', 'feature_2'])
print(tree_rules)

Typical structure (example):

|--- feature_2 <= -0.19
|   |--- class: 0
|--- feature_2 >  -0.19
|   |--- feature_1 <=  0.78
|   |   |--- class: 1
|   |--- feature_1 >   0.78
|   |   |--- class: 1

Root tests feature_2. If ≤ −0.19 → Class 0; otherwise a second test on feature_1 leads to Class 1 leaves. Every threshold and branch is visible, so Decision Trees are a clear form of Explainable AI (XAI).

6. Feature Importance: Why Feature 2 Was Chosen First

importances = tree.feature_importances_
print(f"Feature 1 Importance: {importances[0]:.3f} ({importances[0]*100:.1f}%)")
print(f"Feature 2 Importance: {importances[1]:.3f} ({importances[1]*100:.1f}%)")

Example scores: Feature 1 ≈ 0.082 (8.2%), Feature 2 ≈ 0.918 (91.8%). The higher importance feature is selected for the root split because it yields the largest Gini impurity reduction.

7. Gini Impurity vs Information Gain

Evaluation Metric Gini Impurity (criterion='gini') Information Gain (criterion='entropy')
Primary Goal Minimize class impurity / mixing in child nodes Maximize reduction in entropy (uncertainty)
Optimization Direction Drive value toward 0 Maximize gain
Scikit-Learn Setting Default: criterion='gini' criterion='entropy'
Computational Speed Slightly faster (no logs) Slightly higher cost (log operations)

Lesson Q&A

Import DecisionTreeClassifier from sklearn.tree. Instantiate with hyperparameters such as max_depth=2 and criterion='gini' (or 'entropy'). Call .fit(X, y) with input features X and target labels y.

Use export_text(tree, feature_names=[...]) and print the result. Every threshold and branch is explicit, so users can trace the exact logic behind each prediction—classic Explainable AI (XAI).

It scores candidates with Gini Impurity or Information Gain and picks the feature with the largest impurity reduction. Inspect tree.feature_importances_. In the tutorial example, feature_2 (~0.918) outranked feature_1 (~0.082) and became the root split.

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

ChatGPT 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.

Machine Learning Foundations: Data and Algorithm Labs for Kids in Varna

Varna families exploring AI need concrete, supervised experiments rather than vague hype. Courses show how training examples shape predictions and why models can make mistakes. Students never share personal data, passwords or private family details with AI tools. A standard computer is enough; high-spec hardware is not required.

Digital safety and critical evaluation of AI output are emphasised throughout. Enquire at support@aiandroboticsclub.com or WhatsApp +92 322 4217059. We do not guarantee career outcomes; we focus on genuine understanding of patterns, data and responsible use.

Frequently asked questions

How do students in Varna explore machine learning concepts?

Through visual tools that demonstrate how data sets train computers to recognize images and text.

Are high-spec computers required for AI classes?

No, a standard home computer or laptop with a web browser is all that is needed.

What email address handles registration inquiries?

Send your questions to support@aiandroboticsclub.com.

Explore related learning

SofiaRobotics · Sofia PlovdivPython · Plovdiv ZagrebRobotics · Zagreb