Skip to content
CampusEduX

Problem 4: Visualize a Trained Decision Tree

Easypython
Learn the Concept: Decision Trees

Problem Description

Write a Python program that trains a Decision Tree on a small dataset and visualizes its structure using plot_tree().

Input

A small labeled dataset with feature names.

Output

A displayed tree diagram showing the learned splitting rules.

Constraints

  • At least 6 labeled training examples with 2 features.

Example Input

text
X=[[1,60],[2,65],[8,95],[9,98]], y=[0,0,1,1], feature_names=["hours_studied","attendance"]

Example Output

text
(A tree diagram window showing the learned decision splits, feature names, and class labels)

Concepts Covered

DecisionTreeClassifier, plot_tree().

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 3: Manually Calculate Gini Impurity
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...