Skip to content
CampusEduX

Problem 3: Manually Calculate Gini Impurity

Easypython
Learn the Concept: Decision Trees

Problem Description

Write a Python program that manually calculates the Gini Impurity for a node given the count of samples in each class (without using any built-in function).

Input

A list of class counts (e.g., [6, 4] meaning 6 of Class A, 4 of Class B).

Output

The calculated Gini Impurity.

Constraints

  • At least 2 classes.

Example Input

text
[6, 4]

Example Output

text
Gini Impurity: 0.48

Concepts Covered

Manual Gini formula, proportions, arithmetic.

Related Problems

  • Problem 1: Train a Basic Decision Tree Classifier
    Easy · python
    Solve Problem
  • Problem 2: Compare Trees of Different Depths
    Easy · python
    Solve Problem
  • Problem 4: Visualize a Trained Decision Tree
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...