Skip to content
CampusEduX

Problem 4: Identify the Best max_depth Using Test Error

Easypython
Learn the Concept: Bias-Variance Tradeoff

Problem Description

Write a Python program that trains Decision Trees across a range of max_depth values, and identifies which value produces the LOWEST test error (a simple, manual approach to finding a good complexity balance).

Input

A dataset split into training and test sets, and a range of max_depth values to try.

Output

The max_depth value that produced the lowest test error, along with that error value.

Constraints

  • Test max_depth values from 1 to 10.

Example Input

text
(A dataset split into train/test, testing max_depth 1 through 10)

Example Output

text
Best max_depth: 4 Test MSE at best depth: 0.15

Concepts Covered

Looping, tracking minimum error, DecisionTreeRegressor.

Related Problems

  • Problem 1: Compare Train vs Test Error for a Simple Model
    Easy · python
    Solve Problem
  • Problem 2: Compare Train vs Test Error for an Overly Complex Model
    Easy · python
    Solve Problem
  • Problem 3: Plot Train and Test Error Across Increasing Model Complexity
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...