The Hong Kong Polytechnic University · FACULTY OF COMPUTER SCIENCE

BME5150 Chap.6 Cross Validation and Decision Trees

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 6 of 7 · BME5150

Cross Validation and Decision Trees

Cross-validation rotates a development boundary

In k-fold cross-validation, development data are divided into parts. The pipeline fits on all but one part and validates on the remaining part, rotating until each part has served as validation.

The average summarises development performance, while the variation across folds reveals sensitivity to the partition.

The whole pipeline belongs inside each fold

Imputation, scaling, feature reduction, class resampling and model tuning must be refitted in the training portion of every fold. Selecting features once before cross-validation lets validation outcomes influence the retained columns.

Grouped folds keep all records from one patient together, and stratification helps preserve outcome proportions.

Decision trees partition recursively

A tree tests candidate predictors and thresholds, chooses a split that reduces impurity and repeats the process in child nodes. Leaves return a class or value.

The resulting rules can be read directly when the tree is small, but a deep tree follows development peculiarities and becomes hard to audit.

Entropy and Gini quantify node mixture

Entropy is zero in a pure node and highest for an even binary split. Information gain subtracts the size-weighted child entropy from the parent entropy. Gain ratio reduces the preference for highly fragmenting predictors.

Gini impurity offers another measure of class mixture and often gives similar split choices.

Pruning protects generalisation

Pre-pruning limits depth, minimum leaf size or required improvement. Post-pruning removes weak branches after growth. Both trade some development fit for a simpler structure that may perform better on new cases.

Depth, split criterion and pruning strength are hyperparameters chosen inside development resampling.

In this chapter

What this chapter covers

  • 01

    Five-fold rotation and repeated validation

  • 02

    Grouped and stratified folds

  • 03

    Nested preprocessing and tuning

  • 04

    Recursive decision-tree splits

  • 05

    Entropy, information gain and Gini

  • 06

    Gain ratio and pruning

Worked example · free

Calculate a Gini impurity reduction

Q [9 marks]. AskSia-authored practice. A parent node has 6 positive and 4 negative cases. A split creates children with counts 4/1 and 2/3. Compute parent Gini, weighted child Gini and the reduction. The marks shown are an AskSia study allocation, not a University marking scheme.
The branches route cases through two learned thresholds, and the chosen splits aim to make the child nodes purer.The branches route cases through two learned thresholds, and the chosen splits aim to make the child nodes purer.Feature A ≤ 2.5?Feature B ≤ 7?Mostly positiveLeaf: negativeLeaf: mixedEach split is chosen to reduce impurity in the child nodes
The branches route cases through two learned thresholds, and the chosen splits aim to make the child nodes purer.
  • 3Compute the parent impurity.
  • 4Compute and weight both child impurities.
  • 2Subtract and interpret the reduction.
Parent Gini is 1 − 0.6² − 0.4² = 0.48. The first child has Gini 1 − 0.8² − 0.2² = 0.32 and the second has 1 − 0.4² − 0.6² = 0.48. Both contain five cases, so weighted child impurity is 0.5 × 0.32 + 0.5 × 0.48 = 0.40. The reduction is 0.08. It becomes useful only when compared with alternative candidate splits.
Sia tip — Weight each child by its case count before subtracting; a tiny pure leaf should not dominate the decision.
Glossary

Key terms

Validation Fold
A validation fold is the temporarily held-out development subset used to compare model choices.
Grouped Fold
A grouped fold keeps related records, such as images from one patient, on the same side.
Decision Tree
A decision tree recursively partitions cases through learned predictor conditions into terminal predictions.
Information Gain
Information gain is parent entropy minus the sample-weighted entropy of child nodes.
Gini Impurity
Gini impurity measures class mixture as one minus the sum of squared class proportions.
Pruning
Pruning restricts or removes tree branches to control complexity and variance.
FAQ

Cross Validation and Decision Trees FAQ

Is cross-validation a replacement for a final test set?

Not when it is used to choose algorithms, preprocessing or hyperparameters. Cross-validation is then part of development. Preserve an untouched evaluation set, refit the selected pipeline on development data and apply it once for the final estimate.

Why must all images from one patient stay in the same fold?

Images from one patient share anatomy, acquisition and other patient-specific information. Splitting them across folds lets the model meet close relatives of its validation cases during training, creating an optimistic estimate of performance on new patients.

Why can a perfectly pure tree split still be invalid?

A patient identifier or site code can create pure training nodes by memorising records or institutional patterns. Candidate predictors need intended-use and availability checks before impurity optimisation. Purity is a mathematical property, not proof of clinical validity.

Study strategy

Assessment move

Draw five fold rows and shade a different validation block in each. Under every row, write that preprocessing is refitted on the training blocks. Add a grouping mark around all records from one patient. For trees, compute entropy or Gini from class counts, then practise weighting child impurities before subtraction.

Compare two candidate splits and explain why a high-cardinality identifier can look mathematically attractive but fail transport. Finish by listing the tree hyperparameters that require development tuning and writing the final sequence: tune in folds, prune or limit complexity, refit development data and evaluate once on untouched cases. Redraw an overgrown tree after pruning and state what training detail was sacrificed.

Link that sacrifice to the variance reduction the held-out design is intended to measure.

Working through Cross Validation and Decision Trees in BME5150? Sia is AskSia’s AI Computer Science tutor — ask any BME5150 Cross Validation and Decision Trees question and get a clear, step-by-step explanation grounded in how BME5150 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 16 of your The Hong Kong Polytechnic University subjects - and 1,000+ Bibles across every Australian university.
Sia - your BME5150 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works