Decision Trees

A decision tree predicts a target from features by asking a sequence of yes-or-no questions. Each internal node tests one feature against a threshold . A point goes left if and right otherwise. The leaves split the feature space into boxes , where is the number of leaves of tree . Each leaf predicts one constant:

  • Regression tree: the leaf predicts the mean of the training targets that fall in it.
  • Classification tree: the leaf predicts its majority class, and its class proportions serve as probability estimates.

The standard algorithm is CART (Breiman, Friedman, Olshen and Stone, 1984). It grows the tree greedily, one split at a time. At each node it tries every feature and every threshold halfway between consecutive sorted values. A regression tree picks the pair that minimizes the summed squared error of the two children,

where and are the mean targets in the left and right child. A classification tree instead minimizes the weighted impurity . Here counts the points in the node, and , count those in its children. Three impurity measures are common for a node with class proportions :

  • Gini impurity: , which equals for two classes.
  • Entropy: . The drop in entropy from a split is called the information gain.
  • Misclassification error: . It can rate a split with a pure child no better than one without. CART therefore uses it mainly for pruning.

Growth stops at a maximum depth, a minimum number of points per leaf, or a minimum impurity decrease. Cost-complexity pruning instead grows a large tree . For a penalty , it keeps the subtree that minimizes

Here is the training error of , the summed squared error for regression or the misclassification count for classification. It is a training quantity, unlike the population risk of 2.3. Generalization. Cross-validation picks . A single tree is the easiest model of its family to read and the least accurate. 5.2. Random Forests average many deep trees to cut variance, and 5.3. Gradient Boosted Trees add shallow trees to cut bias.

Intuition

A decision tree is a flowchart that a loan officer or a triage nurse could follow by hand. The first question splits the data into the two groups that differ most in the target. Each group then gets its own best question, and the process repeats until the groups are small or pure. A pure group has one class only. The name comes from the shape of this flowchart. The root holds all the training data. Each leaf holds the points that gave the same answers along its path.

The impurity measures score how mixed a node is. A node with half spam and half legitimate email has Gini , the maximum for two classes. A pure node has Gini . Gini impurity is the error rate of a rule that labels points at random in the node’s class proportions. A good split produces children that are purer than the parent, weighted by their sizes. A tree grown until every leaf is pure fits the training data perfectly and generalizes poorly. Pruning removes the branches whose gain on the training data does not justify their extra leaves.

The animation grows a classification tree one split at a time. Each split cuts one rectangle in two and lowers the weighted Gini impurity.

\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\newcommand{\pa}[1]{\filldraw[draw=black, fill=cold] (#1) circle (2.2pt);}
\newcommand{\pb}[1]{\filldraw[draw=black, fill=white] (#1) ++(-1.9pt,-1.9pt) rectangle ++(3.8pt,3.8pt);}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw[thick] (0,0) rectangle (5.0,5.0);
\node at (2.5,-0.62) {$x_1$};
\node at (-0.95,2.5) {$x_2$};
\draw (0.00,0) -- (0.00,-0.08) node[below] {\footnotesize $0$};
\draw (0,0.00) -- (-0.08,0.00) node[left] {\footnotesize $0$};
\draw (2.50,0) -- (2.50,-0.08) node[below] {\footnotesize $0.5$};
\draw (0,2.50) -- (-0.08,2.50) node[left] {\footnotesize $0.5$};
\draw (5.00,0) -- (5.00,-0.08) node[below] {\footnotesize $1$};
\draw (0,5.00) -- (-0.08,5.00) node[left] {\footnotesize $1$};
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.6s = "false", 17.2s = "false", repeats}}}]
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (9.77,4.64) rectangle (11.37,5.46);
\pa{9.97,5.22}\node[anchor=west] at (10.05,5.22) {\footnotesize $11$};
\pb{10.67,5.22}\node[anchor=west] at (10.75,5.22) {\footnotesize $19$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\node[anchor=west] at (-0.6,-1.25) {One node holds all $30$ points: $11$ blue, $19$ white. Its Gini impurity is $0.464$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.6s = "true", 5.4s = "false", 17.2s = "false", repeats}}}]
\draw[hot, line width=2pt] (0.00,1.50) -- (5.00,1.50);
\node[fill=white, inner sep=1.5pt] at (2.60,1.77) {\footnotesize $x_2 < 0.30$};
\draw (10.57,4.64) -- (8.02,4.06);\node[anchor=east, inner sep=1pt] at (9.18,4.41) {\scriptsize yes};
\draw (10.57,4.64) -- (13.11,4.06);\node[anchor=west, inner sep=1pt] at (11.96,4.41) {\scriptsize no};
\filldraw[draw=hot, line width=1.4pt, fill=white] (9.77,4.64) rectangle (11.37,5.46);
\node at (10.57,5.22) {\footnotesize $x_2 < 0.30$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (7.22,3.24) rectangle (8.82,4.06);
\pa{7.42,3.82}\node[anchor=west] at (7.50,3.82) {\footnotesize $6$};
\pb{8.12,3.82}\node[anchor=west] at (8.20,3.82) {\footnotesize $3$};
\node at (8.02,3.46) {\footnotesize $G = 0.444$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (12.31,3.24) rectangle (13.91,4.06);
\pa{12.51,3.82}\node[anchor=west] at (12.59,3.82) {\footnotesize $5$};
\pb{13.21,3.82}\node[anchor=west] at (13.29,3.82) {\footnotesize $16$};
\node at (13.11,3.46) {\footnotesize $G = 0.363$};
\node[anchor=west] at (-0.6,-1.25) {Split 1, $30$ points: Gini $0.464 \to \frac{9}{30}(0.444) + \frac{21}{30}(0.363) = 0.387$, a drop of $0.077$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.4s = "true", 8.2s = "false", 17.2s = "false", repeats}}}]
\draw[very thick] (0.00,1.50) -- (5.00,1.50);
\draw[hot, line width=2pt] (1.90,0.00) -- (1.90,1.50);
\node[fill=white, inner sep=1.5pt] at (1.13,0.27) {\footnotesize $x_1 < 0.38$};
\draw (10.57,4.64) -- (8.02,4.06);\node[anchor=east, inner sep=1pt] at (9.18,4.41) {\scriptsize yes};
\draw (10.57,4.64) -- (13.11,4.06);\node[anchor=west, inner sep=1pt] at (11.96,4.41) {\scriptsize no};
\draw (8.02,3.24) -- (7.10,2.66);\node[anchor=east, inner sep=1pt] at (7.44,3.01) {\scriptsize yes};
\draw (8.02,3.24) -- (8.95,2.66);\node[anchor=west, inner sep=1pt] at (8.61,3.01) {\scriptsize no};
\filldraw[draw=black, fill=white] (9.77,4.64) rectangle (11.37,5.46);
\node at (10.57,5.22) {\footnotesize $x_2 < 0.30$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\filldraw[draw=hot, line width=1.4pt, fill=white] (7.22,3.24) rectangle (8.82,4.06);
\node at (8.02,3.82) {\footnotesize $x_1 < 0.38$};
\node at (8.02,3.46) {\footnotesize $G = 0.444$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (12.31,3.24) rectangle (13.91,4.06);
\pa{12.51,3.82}\node[anchor=west] at (12.59,3.82) {\footnotesize $5$};
\pb{13.21,3.82}\node[anchor=west] at (13.29,3.82) {\footnotesize $16$};
\node at (13.11,3.46) {\footnotesize $G = 0.363$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (6.30,1.84) rectangle (7.90,2.66);
\pa{6.50,2.42}\node[anchor=west] at (6.58,2.42) {\footnotesize $0$};
\pb{7.20,2.42}\node[anchor=west] at (7.28,2.42) {\footnotesize $3$};
\node at (7.10,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (8.15,1.84) rectangle (9.75,2.66);
\pa{8.35,2.42}\node[anchor=west] at (8.43,2.42) {\footnotesize $6$};
\pb{9.05,2.42}\node[anchor=west] at (9.13,2.42) {\footnotesize $0$};
\node at (8.95,2.06) {\footnotesize $G = 0.000$};
\node[anchor=west] at (-0.6,-1.25) {Split 2, $9$ points: Gini $0.444 \to \frac{3}{9}(0.000) + \frac{6}{9}(0.000) = 0.000$, a drop of $0.444$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.2s = "true", 11s = "false", 17.2s = "false", repeats}}}]
\draw[very thick] (0.00,1.50) -- (5.00,1.50);
\draw[very thick] (1.90,0.00) -- (1.90,1.50);
\draw[hot, line width=2pt] (2.10,1.50) -- (2.10,5.00);
\node[fill=white, inner sep=1.5pt] at (1.33,3.60) {\footnotesize $x_1 < 0.42$};
\draw (10.57,4.64) -- (8.02,4.06);\node[anchor=east, inner sep=1pt] at (9.18,4.41) {\scriptsize yes};
\draw (10.57,4.64) -- (13.11,4.06);\node[anchor=west, inner sep=1pt] at (11.96,4.41) {\scriptsize no};
\draw (8.02,3.24) -- (7.10,2.66);\node[anchor=east, inner sep=1pt] at (7.44,3.01) {\scriptsize yes};
\draw (8.02,3.24) -- (8.95,2.66);\node[anchor=west, inner sep=1pt] at (8.61,3.01) {\scriptsize no};
\draw (13.11,3.24) -- (11.73,2.66);\node[anchor=east, inner sep=1pt] at (12.30,3.01) {\scriptsize yes};
\draw (13.11,3.24) -- (14.50,2.66);\node[anchor=west, inner sep=1pt] at (13.93,3.01) {\scriptsize no};
\filldraw[draw=black, fill=white] (9.77,4.64) rectangle (11.37,5.46);
\node at (10.57,5.22) {\footnotesize $x_2 < 0.30$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\filldraw[draw=black, fill=white] (7.22,3.24) rectangle (8.82,4.06);
\node at (8.02,3.82) {\footnotesize $x_1 < 0.38$};
\node at (8.02,3.46) {\footnotesize $G = 0.444$};
\filldraw[draw=hot, line width=1.4pt, fill=white] (12.31,3.24) rectangle (13.91,4.06);
\node at (13.11,3.82) {\footnotesize $x_1 < 0.42$};
\node at (13.11,3.46) {\footnotesize $G = 0.363$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (6.30,1.84) rectangle (7.90,2.66);
\pa{6.50,2.42}\node[anchor=west] at (6.58,2.42) {\footnotesize $0$};
\pb{7.20,2.42}\node[anchor=west] at (7.28,2.42) {\footnotesize $3$};
\node at (7.10,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (8.15,1.84) rectangle (9.75,2.66);
\pa{8.35,2.42}\node[anchor=west] at (8.43,2.42) {\footnotesize $6$};
\pb{9.05,2.42}\node[anchor=west] at (9.13,2.42) {\footnotesize $0$};
\node at (8.95,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (10.93,1.84) rectangle (12.53,2.66);
\pa{11.13,2.42}\node[anchor=west] at (11.21,2.42) {\footnotesize $5$};
\pb{11.83,2.42}\node[anchor=west] at (11.91,2.42) {\footnotesize $4$};
\node at (11.73,2.06) {\footnotesize $G = 0.494$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (13.70,1.84) rectangle (15.30,2.66);
\pa{13.90,2.42}\node[anchor=west] at (13.98,2.42) {\footnotesize $0$};
\pb{14.60,2.42}\node[anchor=west] at (14.68,2.42) {\footnotesize $12$};
\node at (14.50,2.06) {\footnotesize $G = 0.000$};
\node[anchor=west] at (-0.6,-1.25) {Split 3, $21$ points: Gini $0.363 \to \frac{9}{21}(0.494) + \frac{12}{21}(0.000) = 0.212$, a drop of $0.151$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 11s = "true", 13.8s = "false", 17.2s = "false", repeats}}}]
\draw[very thick] (0.00,1.50) -- (5.00,1.50);
\draw[very thick] (1.90,0.00) -- (1.90,1.50);
\draw[very thick] (2.10,1.50) -- (2.10,5.00);
\draw[hot, line width=2pt] (0.00,2.75) -- (2.10,2.75);
\node[fill=white, inner sep=1.5pt] at (0.80,3.02) {\footnotesize $x_2 < 0.55$};
\draw (10.57,4.64) -- (8.02,4.06);\node[anchor=east, inner sep=1pt] at (9.18,4.41) {\scriptsize yes};
\draw (10.57,4.64) -- (13.11,4.06);\node[anchor=west, inner sep=1pt] at (11.96,4.41) {\scriptsize no};
\draw (8.02,3.24) -- (7.10,2.66);\node[anchor=east, inner sep=1pt] at (7.44,3.01) {\scriptsize yes};
\draw (8.02,3.24) -- (8.95,2.66);\node[anchor=west, inner sep=1pt] at (8.61,3.01) {\scriptsize no};
\draw (13.11,3.24) -- (11.73,2.66);\node[anchor=east, inner sep=1pt] at (12.30,3.01) {\scriptsize yes};
\draw (13.11,3.24) -- (14.50,2.66);\node[anchor=west, inner sep=1pt] at (13.93,3.01) {\scriptsize no};
\draw (11.73,1.84) -- (10.80,1.26);\node[anchor=east, inner sep=1pt] at (11.14,1.61) {\scriptsize yes};
\draw (11.73,1.84) -- (12.65,1.26);\node[anchor=west, inner sep=1pt] at (12.31,1.61) {\scriptsize no};
\filldraw[draw=black, fill=white] (9.77,4.64) rectangle (11.37,5.46);
\node at (10.57,5.22) {\footnotesize $x_2 < 0.30$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\filldraw[draw=black, fill=white] (7.22,3.24) rectangle (8.82,4.06);
\node at (8.02,3.82) {\footnotesize $x_1 < 0.38$};
\node at (8.02,3.46) {\footnotesize $G = 0.444$};
\filldraw[draw=black, fill=white] (12.31,3.24) rectangle (13.91,4.06);
\node at (13.11,3.82) {\footnotesize $x_1 < 0.42$};
\node at (13.11,3.46) {\footnotesize $G = 0.363$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (6.30,1.84) rectangle (7.90,2.66);
\pa{6.50,2.42}\node[anchor=west] at (6.58,2.42) {\footnotesize $0$};
\pb{7.20,2.42}\node[anchor=west] at (7.28,2.42) {\footnotesize $3$};
\node at (7.10,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (8.15,1.84) rectangle (9.75,2.66);
\pa{8.35,2.42}\node[anchor=west] at (8.43,2.42) {\footnotesize $6$};
\pb{9.05,2.42}\node[anchor=west] at (9.13,2.42) {\footnotesize $0$};
\node at (8.95,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=hot, line width=1.4pt, fill=white] (10.93,1.84) rectangle (12.53,2.66);
\node at (11.73,2.42) {\footnotesize $x_2 < 0.55$};
\node at (11.73,2.06) {\footnotesize $G = 0.494$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (13.70,1.84) rectangle (15.30,2.66);
\pa{13.90,2.42}\node[anchor=west] at (13.98,2.42) {\footnotesize $0$};
\pb{14.60,2.42}\node[anchor=west] at (14.68,2.42) {\footnotesize $12$};
\node at (14.50,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (10.00,0.44) rectangle (11.60,1.26);
\pa{10.20,1.02}\node[anchor=west] at (10.28,1.02) {\footnotesize $1$};
\pb{10.90,1.02}\node[anchor=west] at (10.98,1.02) {\footnotesize $4$};
\node at (10.80,0.66) {\footnotesize $G = 0.320$};
\filldraw[draw=hot, line width=1.4pt, fill=white, rounded corners=3pt] (11.85,0.44) rectangle (13.45,1.26);
\pa{12.05,1.02}\node[anchor=west] at (12.13,1.02) {\footnotesize $4$};
\pb{12.75,1.02}\node[anchor=west] at (12.83,1.02) {\footnotesize $0$};
\node at (12.65,0.66) {\footnotesize $G = 0.000$};
\node[anchor=west] at (-0.6,-1.25) {Split 4, $9$ points: Gini $0.494 \to \frac{5}{9}(0.320) + \frac{4}{9}(0.000) = 0.178$, a drop of $0.316$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 13.8s = "true", 17.2s = "true", repeats}}}]
\draw[very thick] (0.00,1.50) -- (5.00,1.50);
\draw[very thick] (1.90,0.00) -- (1.90,1.50);
\draw[very thick] (2.10,1.50) -- (2.10,5.00);
\draw[very thick] (0.00,2.75) -- (2.10,2.75);
\draw (10.57,4.64) -- (8.02,4.06);\node[anchor=east, inner sep=1pt] at (9.18,4.41) {\scriptsize yes};
\draw (10.57,4.64) -- (13.11,4.06);\node[anchor=west, inner sep=1pt] at (11.96,4.41) {\scriptsize no};
\draw (8.02,3.24) -- (7.10,2.66);\node[anchor=east, inner sep=1pt] at (7.44,3.01) {\scriptsize yes};
\draw (8.02,3.24) -- (8.95,2.66);\node[anchor=west, inner sep=1pt] at (8.61,3.01) {\scriptsize no};
\draw (13.11,3.24) -- (11.73,2.66);\node[anchor=east, inner sep=1pt] at (12.30,3.01) {\scriptsize yes};
\draw (13.11,3.24) -- (14.50,2.66);\node[anchor=west, inner sep=1pt] at (13.93,3.01) {\scriptsize no};
\draw (11.73,1.84) -- (10.80,1.26);\node[anchor=east, inner sep=1pt] at (11.14,1.61) {\scriptsize yes};
\draw (11.73,1.84) -- (12.65,1.26);\node[anchor=west, inner sep=1pt] at (12.31,1.61) {\scriptsize no};
\filldraw[draw=black, fill=white] (9.77,4.64) rectangle (11.37,5.46);
\node at (10.57,5.22) {\footnotesize $x_2 < 0.30$};
\node at (10.57,4.86) {\footnotesize $G = 0.464$};
\filldraw[draw=black, fill=white] (7.22,3.24) rectangle (8.82,4.06);
\node at (8.02,3.82) {\footnotesize $x_1 < 0.38$};
\node at (8.02,3.46) {\footnotesize $G = 0.444$};
\filldraw[draw=black, fill=white] (12.31,3.24) rectangle (13.91,4.06);
\node at (13.11,3.82) {\footnotesize $x_1 < 0.42$};
\node at (13.11,3.46) {\footnotesize $G = 0.363$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (6.30,1.84) rectangle (7.90,2.66);
\pa{6.50,2.42}\node[anchor=west] at (6.58,2.42) {\footnotesize $0$};
\pb{7.20,2.42}\node[anchor=west] at (7.28,2.42) {\footnotesize $3$};
\node at (7.10,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (8.15,1.84) rectangle (9.75,2.66);
\pa{8.35,2.42}\node[anchor=west] at (8.43,2.42) {\footnotesize $6$};
\pb{9.05,2.42}\node[anchor=west] at (9.13,2.42) {\footnotesize $0$};
\node at (8.95,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=black, fill=white] (10.93,1.84) rectangle (12.53,2.66);
\node at (11.73,2.42) {\footnotesize $x_2 < 0.55$};
\node at (11.73,2.06) {\footnotesize $G = 0.494$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (13.70,1.84) rectangle (15.30,2.66);
\pa{13.90,2.42}\node[anchor=west] at (13.98,2.42) {\footnotesize $0$};
\pb{14.60,2.42}\node[anchor=west] at (14.68,2.42) {\footnotesize $12$};
\node at (14.50,2.06) {\footnotesize $G = 0.000$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (10.00,0.44) rectangle (11.60,1.26);
\pa{10.20,1.02}\node[anchor=west] at (10.28,1.02) {\footnotesize $1$};
\pb{10.90,1.02}\node[anchor=west] at (10.98,1.02) {\footnotesize $4$};
\node at (10.80,0.66) {\footnotesize $G = 0.320$};
\filldraw[draw=black, fill=white, rounded corners=3pt] (11.85,0.44) rectangle (13.45,1.26);
\pa{12.05,1.02}\node[anchor=west] at (12.13,1.02) {\footnotesize $4$};
\pb{12.75,1.02}\node[anchor=west] at (12.83,1.02) {\footnotesize $0$};
\node at (12.65,0.66) {\footnotesize $G = 0.000$};
\node at (6.96,1.58) {\footnotesize predict};\pb{7.60,1.59}
\node at (8.81,1.58) {\footnotesize predict};\pa{9.45,1.59}
\node at (10.66,0.18) {\footnotesize predict};\pb{11.30,0.19}
\node at (12.51,0.18) {\footnotesize predict};\pa{13.15,0.19}
\node at (14.36,1.58) {\footnotesize predict};\pb{15.00,1.59}
\node[anchor=west] at (-0.6,-1.25) {Depth $3$ reached. Each of the $5$ leaves predicts its majority class.};
\end{scope}
\pb{3.10,4.35}\pa{3.75,1.25}\pa{1.60,4.20}\pa{0.20,4.00}\pb{3.85,2.35}\pb{1.60,1.65}\pb{1.35,2.25}\pb{2.50,2.75}\pb{4.80,3.85}\pb{3.05,4.75}\pb{1.20,0.95}\pa{3.00,0.40}\pa{0.35,2.55}\pb{2.35,4.40}\pb{3.10,2.55}\pa{2.50,1.35}\pb{0.25,1.10}\pa{3.40,1.10}\pa{2.05,0.30}\pa{4.00,0.90}\pa{1.45,4.25}\pb{2.75,3.90}\pb{3.15,3.60}\pb{0.60,2.60}\pb{2.55,4.20}\pa{1.85,2.95}\pb{0.45,2.00}\pb{1.70,0.90}\pb{3.95,1.95}\pb{4.70,2.90}
\end{tikzpicture}
\end{document}

Properties

(Greedy Search) CART picks the best split at each node and never revisits it, so it can miss a better tree.

Hyafil and Rivest (1976) showed that building an optimal binary decision tree is NP-complete. CART therefore optimizes one split at a time. Sorting all features at the root costs . A split that looks useless now can enable strong splits below it. On XOR-shaped data, the class is positive when exactly one of two features is high. No single split then lowers the impurity. A rule that stops when the impurity decrease is small would stop at the root. CART therefore grows a large tree first and prunes it afterward.

(High Variance) A small change in the training data can change the root split and every split below it.

Two features may give nearly the same impurity decrease at the root. Resampling the data can swap the winner. Each child node then receives different points, and the whole tree below changes. A deep tree has low bias, since its boxes can follow almost any shape. It also has high variance, since each leaf averages only a few points. In the bias-variance decomposition, a deeper tree has lower bias and higher variance. Bagging and random forests average many trees to reduce this variance.

(Axis-Aligned Boxes) Every split is perpendicular to one feature axis, so a tree approximates an oblique boundary with a staircase.

A boundary such as needs many alternating splits on and . A linear classifier needs one. Rotating the features can therefore change a tree’s accuracy a lot. The constant leaves also limit regression trees. A regression tree never predicts outside the range of its training targets, so it cannot extrapolate a trend. A tree trained on homes up to two million dollars cannot predict a higher price for a mansion.

A regression tree predicts one number per leaf. Over two features, its prediction is a set of flat blocks, one per rectangle.

\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\newcommand{\pt}[1]{\filldraw[draw=black, fill=hot] (#1) circle (2.2pt);}
\newcommand{\ph}[1]{\filldraw[draw=hot, thick, fill=white] (#1) circle (2pt);}
\newcommand{\rs}[2]{\draw (#1) -- (#2);}
\newcommand{\rd}[2]{\draw[dashed] (#1) -- (#2);}
\newcommand{\st}[2]{\draw[mid] (#1) -- (#2);}
\newcommand{\tp}[1]{\filldraw[draw=black, fill=cold] #1;}
\newcommand{\sd}[1]{\filldraw[draw=black, fill=white] #1;}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 10.68s = "true", repeats}}}]
\draw[thick] (8.3,-1.5) rectangle (12.9,3.0999999999999996);
\node at (10.60,-1.85) {$x_1$};
\node at (7.95,0.80) {$x_2$};
\node at (10.60,3.45) {seen from above: $\hat y$ per leaf};
\draw (8.30,-1.50) rectangle (10.32,0.43);
\draw (8.30,0.43) rectangle (10.32,1.01);
\draw (10.32,-1.50) rectangle (12.90,-0.01);
\draw (10.32,-0.01) rectangle (12.90,1.01);
\draw (8.30,1.01) rectangle (10.62,2.29);
\draw (8.30,2.29) rectangle (10.62,3.10);
\draw (10.62,1.01) rectangle (11.18,3.10);
\draw (11.18,1.01) rectangle (12.90,3.10);
\node[inner sep=1pt] at (9.31,-0.53) {\footnotesize $0.41$};
\node[inner sep=1pt] at (9.31,0.72) {\footnotesize $0.54$};
\node[inner sep=1pt] at (11.61,-0.75) {\footnotesize $0.62$};
\node[inner sep=1pt] at (11.61,0.50) {\footnotesize $0.94$};
\node[inner sep=1pt] at (9.46,1.65) {\footnotesize $0.87$};
\node[inner sep=1pt] at (9.46,2.70) {\footnotesize $1.16$};
\node[inner sep=1pt, rotate=90] at (10.90,2.05) {\footnotesize $1.37$};
\node[inner sep=1pt] at (12.04,2.05) {\footnotesize $1.60$};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (4.24,-0.69) -- (6.89,0.41) -- (2.65,1.10) -- cycle;
\node at (1.80,-0.47) {$x_1$};
\node at (6.07,-0.22) {$x_2$};
\st{2.25,0.86}{2.25,2.29}\pt{2.25,2.29}
\st{3.47,0.75}{3.47,3.33}\pt{3.47,3.33}
\st{3.57,0.72}{3.57,2.86}\pt{3.57,2.86}
\st{1.61,0.52}{1.61,1.19}\pt{1.61,1.19}
\st{4.35,0.65}{4.35,3.35}\pt{4.35,3.35}
\st{5.13,0.64}{5.13,3.74}\pt{5.13,3.74}
\st{1.94,0.51}{1.94,1.92}\pt{1.94,1.92}
\st{4.41,0.58}{4.41,3.39}\pt{4.41,3.39}
\st{4.36,0.56}{4.36,3.23}\pt{4.36,3.23}
\st{4.93,0.53}{4.93,3.57}\pt{4.93,3.57}
\st{1.41,0.37}{1.41,1.17}\pt{1.41,1.17}
\st{3.13,0.39}{3.13,2.22}\pt{3.13,2.22}
\st{2.34,0.31}{2.34,1.69}\pt{2.34,1.69}
\st{4.61,0.37}{4.61,3.11}\pt{4.61,3.11}
\st{0.73,0.20}{0.73,1.22}\pt{0.73,1.22}
\st{3.58,0.26}{3.58,2.53}\pt{3.58,2.53}
\st{2.08,0.11}{2.08,1.15}\pt{2.08,1.15}
\st{1.45,0.04}{1.45,0.77}\pt{1.45,0.77}
\st{3.98,0.13}{3.98,2.26}\pt{3.98,2.26}
\st{6.18,0.19}{6.18,4.36}\pt{6.18,4.36}
\st{1.85,-0.04}{1.85,0.93}\pt{1.85,0.93}
\st{4.55,-0.02}{4.55,1.96}\pt{4.55,1.96}
\st{2.81,-0.06}{2.81,1.56}\pt{2.81,1.56}
\st{5.56,-0.01}{5.56,3.29}\pt{5.56,3.29}
\st{4.43,-0.12}{4.43,1.80}\pt{4.43,1.80}
\st{1.69,-0.23}{1.69,0.38}\pt{1.69,0.38}
\st{3.47,-0.22}{3.47,1.02}\pt{3.47,1.02}
\st{3.86,-0.26}{3.86,1.26}\pt{3.86,1.26}
\st{2.77,-0.34}{2.77,0.67}\pt{2.77,0.67}
\st{3.91,-0.36}{3.91,0.86}\pt{3.91,0.86}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {$30$ training points: a response $y$ measured over $(x_1, x_2)$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 5.2s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (4.24,-0.69) -- (6.89,0.41) -- (2.65,1.10) -- cycle;
\node at (1.80,-0.47) {$x_1$};
\node at (6.07,-0.22) {$x_2$};
\draw[mid] (1.44,0.60) -- (5.68,-0.09);
\draw[mid] (1.87,-0.30) -- (3.31,0.30);
\draw[mid] (1.11,0.46) -- (2.98,0.16);
\draw[mid] (2.73,0.05) -- (5.10,-0.33);
\draw[mid] (3.59,0.25) -- (4.79,0.75);
\draw[mid] (2.19,0.91) -- (4.33,0.56);
\draw[mid] (4.09,0.17) -- (5.30,0.67);
\rd{3.57,2.86}{3.57,3.19}\ph{3.57,2.86}
\sd{(4.33,3.00) -- (4.79,3.19) -- (4.79,3.26) -- (4.33,3.06) -- cycle}\sd{(2.19,3.34) -- (4.33,3.00) -- (4.33,3.06) -- (2.19,3.41) -- cycle}\tp{(2.19,3.41) -- (4.33,3.06) -- (4.79,3.26) -- (2.65,3.60) -- cycle}
\rs{3.47,3.22}{3.47,3.33}\pt{3.47,3.33}
\rs{4.35,3.12}{4.35,3.35}\pt{4.35,3.35}
\rd{2.25,2.29}{2.25,2.70}\ph{2.25,2.29}
\rd{3.13,2.22}{3.13,2.24}\ph{3.13,2.22}
\sd{(3.59,2.06) -- (4.33,2.37) -- (4.33,2.44) -- (3.59,2.13) -- cycle}\sd{(1.44,2.41) -- (3.59,2.06) -- (3.59,2.13) -- (1.44,2.48) -- cycle}\tp{(1.44,2.48) -- (3.59,2.13) -- (4.33,2.44) -- (2.19,2.78) -- cycle}
\rs{3.58,2.10}{3.58,2.53}\pt{3.58,2.53}
\rd{4.41,3.39}{4.41,3.49}\ph{4.41,3.39}
\rd{4.36,3.23}{4.36,3.47}\ph{4.36,3.23}
\sd{(4.09,3.04) -- (5.30,3.54) -- (5.30,3.61) -- (4.09,3.11) -- cycle}\sd{(3.59,3.12) -- (4.09,3.04) -- (4.09,3.11) -- (3.59,3.19) -- cycle}\tp{(3.59,3.19) -- (4.09,3.11) -- (5.30,3.61) -- (4.79,3.69) -- cycle}
\rs{5.13,3.54}{5.13,3.74}\pt{5.13,3.74}
\rs{4.93,3.44}{4.93,3.57}\pt{4.93,3.57}
\rd{4.61,3.11}{4.61,3.77}\ph{4.61,3.11}
\rd{5.56,3.29}{5.56,3.39}\ph{5.56,3.29}
\sd{(5.68,3.28) -- (6.89,3.78) -- (6.89,3.85) -- (5.68,3.35) -- cycle}\sd{(4.09,3.54) -- (5.68,3.28) -- (5.68,3.35) -- (4.09,3.61) -- cycle}\tp{(4.09,3.61) -- (5.68,3.35) -- (6.89,3.85) -- (5.30,4.11) -- cycle}
\rs{6.18,3.59}{6.18,4.36}\pt{6.18,4.36}
\rd{1.61,1.19}{1.61,1.67}\ph{1.61,1.19}
\sd{(2.98,1.28) -- (3.31,1.41) -- (3.31,1.48) -- (2.98,1.35) -- cycle}\sd{(1.11,1.58) -- (2.98,1.28) -- (2.98,1.35) -- (1.11,1.65) -- cycle}\tp{(1.11,1.65) -- (2.98,1.35) -- (3.31,1.48) -- (1.44,1.78) -- cycle}
\rs{1.94,1.66}{1.94,1.92}\pt{1.94,1.92}
\rs{2.34,1.46}{2.34,1.69}\pt{2.34,1.69}
\rd{1.41,1.17}{1.41,1.23}\ph{1.41,1.17}
\rd{1.45,0.77}{1.45,0.90}\ph{1.45,0.77}
\rd{1.69,0.38}{1.69,0.63}\ph{1.69,0.38}
\sd{(1.87,0.53) -- (2.98,0.99) -- (2.98,1.06) -- (1.87,0.59) -- cycle}\sd{(0.00,0.83) -- (1.87,0.53) -- (1.87,0.59) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.87,0.59) -- (2.98,1.06) -- (1.11,1.36) -- cycle}
\rs{0.73,1.07}{0.73,1.22}\pt{0.73,1.22}
\rs{2.08,0.97}{2.08,1.15}\pt{2.08,1.15}
\rs{1.85,0.82}{1.85,0.93}\pt{1.85,0.93}
\rd{4.55,1.96}{4.55,1.99}\ph{4.55,1.96}
\rd{4.43,1.80}{4.43,1.89}\ph{4.43,1.80}
\sd{(5.10,1.64) -- (5.68,1.88) -- (5.68,1.95) -- (5.10,1.71) -- cycle}\sd{(2.73,2.03) -- (5.10,1.64) -- (5.10,1.71) -- (2.73,2.09) -- cycle}\tp{(2.73,2.09) -- (5.10,1.71) -- (5.68,1.95) -- (3.31,2.34) -- cycle}
\rs{3.98,2.14}{3.98,2.26}\pt{3.98,2.26}
\rd{3.47,1.02}{3.47,1.10}\ph{3.47,1.02}
\rd{2.77,0.67}{2.77,0.98}\ph{2.77,0.67}
\rd{3.91,0.86}{3.91,0.96}\ph{3.91,0.86}
\sd{(4.24,0.60) -- (5.10,0.96) -- (5.10,1.03) -- (4.24,0.67) -- cycle}\sd{(1.87,0.99) -- (4.24,0.60) -- (4.24,0.67) -- (1.87,1.05) -- cycle}\tp{(1.87,1.05) -- (4.24,0.67) -- (5.10,1.03) -- (2.73,1.41) -- cycle}
\rs{2.81,1.27}{2.81,1.56}\pt{2.81,1.56}
\rs{3.86,1.06}{3.86,1.26}\pt{3.86,1.26}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {A depth-$3$ tree: each of the $8$ leaves predicts the mean $y$ of its rectangle.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.2s = "true", 5.46s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (4.18,-0.71) -- (6.93,0.37) -- (2.75,1.08) -- cycle;
\node at (1.76,-0.49) {$x_1$};
\node at (6.05,-0.26) {$x_2$};
\draw[mid] (1.50,0.59) -- (5.67,-0.12);
\draw[mid] (1.84,-0.31) -- (3.34,0.28);
\draw[mid] (1.16,0.45) -- (2.99,0.14);
\draw[mid] (2.73,0.04) -- (5.07,-0.36);
\draw[mid] (3.61,0.23) -- (4.86,0.72);
\draw[mid] (2.27,0.89) -- (4.38,0.53);
\draw[mid] (4.11,0.14) -- (5.36,0.64);
\rd{3.63,2.84}{3.63,3.17}\ph{3.63,2.84}
\sd{(4.38,2.97) -- (4.86,3.16) -- (4.86,3.23) -- (4.38,3.04) -- cycle}\sd{(2.27,3.33) -- (4.38,2.97) -- (4.38,3.04) -- (2.27,3.40) -- cycle}\tp{(2.27,3.40) -- (4.38,3.04) -- (4.86,3.23) -- (2.75,3.59) -- cycle}
\rs{3.53,3.20}{3.53,3.31}\pt{3.53,3.31}
\rs{4.41,3.10}{4.41,3.33}\pt{4.41,3.33}
\rd{2.33,2.27}{2.33,2.69}\ph{2.33,2.27}
\rd{3.17,2.21}{3.17,2.22}\ph{3.17,2.21}
\sd{(3.61,2.04) -- (4.38,2.34) -- (4.38,2.41) -- (3.61,2.11) -- cycle}\sd{(1.50,2.40) -- (3.61,2.04) -- (3.61,2.11) -- (1.50,2.47) -- cycle}\tp{(1.50,2.47) -- (3.61,2.11) -- (4.38,2.41) -- (2.27,2.77) -- cycle}
\rs{3.60,2.08}{3.60,2.51}\pt{3.60,2.51}
\rd{4.47,3.36}{4.47,3.46}\ph{4.47,3.36}
\rd{4.41,3.21}{4.41,3.44}\ph{4.41,3.21}
\sd{(4.11,3.02) -- (5.36,3.51) -- (5.36,3.58) -- (4.11,3.08) -- cycle}\sd{(3.61,3.10) -- (4.11,3.02) -- (4.11,3.08) -- (3.61,3.17) -- cycle}\tp{(3.61,3.17) -- (4.11,3.08) -- (5.36,3.58) -- (4.86,3.66) -- cycle}
\rs{5.19,3.51}{5.19,3.71}\pt{5.19,3.71}
\rs{4.98,3.40}{4.98,3.54}\pt{4.98,3.54}
\rd{4.64,3.08}{4.64,3.74}\ph{4.64,3.08}
\rd{5.56,3.25}{5.56,3.35}\ph{5.56,3.25}
\sd{(5.67,3.25) -- (6.93,3.74) -- (6.93,3.81) -- (5.67,3.31) -- cycle}\sd{(4.11,3.51) -- (5.67,3.25) -- (5.67,3.31) -- (4.11,3.58) -- cycle}\tp{(4.11,3.58) -- (5.67,3.31) -- (6.93,3.81) -- (5.36,4.07) -- cycle}
\rs{6.20,3.56}{6.20,4.32}\pt{6.20,4.32}
\rd{1.65,1.18}{1.65,1.66}\ph{1.65,1.18}
\sd{(2.99,1.26) -- (3.34,1.39) -- (3.34,1.46) -- (2.99,1.33) -- cycle}\sd{(1.16,1.57) -- (2.99,1.26) -- (2.99,1.33) -- (1.16,1.64) -- cycle}\tp{(1.16,1.64) -- (2.99,1.33) -- (3.34,1.46) -- (1.50,1.78) -- cycle}
\rs{1.99,1.65}{1.99,1.90}\pt{1.99,1.90}
\rs{2.37,1.45}{2.37,1.68}\pt{2.37,1.68}
\rd{1.45,1.16}{1.45,1.22}\ph{1.45,1.16}
\rd{1.46,0.76}{1.46,0.89}\ph{1.46,0.76}
\rd{1.67,0.37}{1.67,0.62}\ph{1.67,0.37}
\sd{(1.84,0.52) -- (2.99,0.97) -- (2.99,1.04) -- (1.84,0.58) -- cycle}\sd{(0.00,0.83) -- (1.84,0.52) -- (1.84,0.58) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.84,0.58) -- (2.99,1.04) -- (1.16,1.35) -- cycle}
\rs{0.74,1.06}{0.74,1.22}\pt{0.74,1.22}
\rs{2.09,0.95}{2.09,1.13}\pt{2.09,1.13}
\rs{1.85,0.81}{1.85,0.92}\pt{1.85,0.92}
\rd{4.55,1.93}{4.55,1.96}\ph{4.55,1.93}
\rd{4.41,1.77}{4.41,1.86}\ph{4.41,1.77}
\sd{(5.07,1.61) -- (5.67,1.85) -- (5.67,1.92) -- (5.07,1.68) -- cycle}\sd{(2.73,2.01) -- (5.07,1.61) -- (5.07,1.68) -- (2.73,2.08) -- cycle}\tp{(2.73,2.08) -- (5.07,1.68) -- (5.67,1.92) -- (3.34,2.32) -- cycle}
\rs{3.99,2.12}{3.99,2.23}\pt{3.99,2.23}
\rd{3.44,1.00}{3.44,1.08}\ph{3.44,1.00}
\rd{2.74,0.65}{2.74,0.96}\ph{2.74,0.65}
\rd{3.88,0.84}{3.88,0.94}\ph{3.88,0.84}
\sd{(4.18,0.58) -- (5.07,0.93) -- (5.07,1.00) -- (4.18,0.64) -- cycle}\sd{(1.84,0.98) -- (4.18,0.58) -- (4.18,0.64) -- (1.84,1.04) -- cycle}\tp{(1.84,1.04) -- (4.18,0.64) -- (5.07,1.00) -- (2.73,1.39) -- cycle}
\rs{2.80,1.25}{2.80,1.55}\pt{2.80,1.55}
\rs{3.83,1.04}{3.83,1.23}\pt{3.83,1.23}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.46s = "true", 5.72s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (3.99,-0.78) -- (7.00,0.25) -- (3.01,1.03) -- cycle;
\node at (1.63,-0.51) {$x_1$};
\node at (5.98,-0.36) {$x_2$};
\draw[mid] (1.64,0.56) -- (5.63,-0.22);
\draw[mid] (1.76,-0.34) -- (3.40,0.22);
\draw[mid] (1.27,0.43) -- (3.02,0.09);
\draw[mid] (2.73,-0.01) -- (4.97,-0.44);
\draw[mid] (3.66,0.17) -- (5.03,0.64);
\draw[mid] (2.49,0.85) -- (4.50,0.46);
\draw[mid] (4.14,0.08) -- (5.51,0.55);
\rd{3.80,2.77}{3.80,3.11}\ph{3.80,2.77}
\sd{(4.50,2.90) -- (5.03,3.08) -- (5.03,3.14) -- (4.50,2.96) -- cycle}\sd{(2.49,3.29) -- (4.50,2.90) -- (4.50,2.96) -- (2.49,3.36) -- cycle}\tp{(2.49,3.36) -- (4.50,2.96) -- (5.03,3.14) -- (3.01,3.54) -- cycle}
\rs{3.71,3.14}{3.71,3.25}\pt{3.71,3.25}
\rs{4.56,3.02}{4.56,3.25}\pt{4.56,3.25}
\rd{2.53,2.23}{2.53,2.65}\ph{2.53,2.23}
\rd{3.25,2.15}{3.25,2.16}\ph{3.25,2.15}
\sd{(3.66,1.98) -- (4.50,2.27) -- (4.50,2.34) -- (3.66,2.05) -- cycle}\sd{(1.64,2.37) -- (3.66,1.98) -- (3.66,2.05) -- (1.64,2.44) -- cycle}\tp{(1.64,2.44) -- (3.66,2.05) -- (4.50,2.34) -- (2.49,2.73) -- cycle}
\rs{3.65,2.02}{3.65,2.45}\pt{3.65,2.45}
\rd{4.60,3.28}{4.60,3.39}\ph{4.60,3.28}
\rd{4.54,3.13}{4.54,3.37}\ph{4.54,3.13}
\sd{(4.14,2.95) -- (5.51,3.42) -- (5.51,3.48) -- (4.14,3.01) -- cycle}\sd{(3.66,3.04) -- (4.14,2.95) -- (4.14,3.01) -- (3.66,3.11) -- cycle}\tp{(3.66,3.11) -- (4.14,3.01) -- (5.51,3.48) -- (5.03,3.58) -- cycle}
\rs{5.33,3.42}{5.33,3.62}\pt{5.33,3.62}
\rs{5.10,3.32}{5.10,3.45}\pt{5.10,3.45}
\rd{4.71,3.01}{4.71,3.67}\ph{4.71,3.01}
\rd{5.54,3.16}{5.54,3.26}\ph{5.54,3.16}
\sd{(5.63,3.15) -- (7.00,3.62) -- (7.00,3.69) -- (5.63,3.22) -- cycle}\sd{(4.14,3.45) -- (5.63,3.15) -- (5.63,3.22) -- (4.14,3.51) -- cycle}\tp{(4.14,3.51) -- (5.63,3.22) -- (7.00,3.69) -- (5.51,3.98) -- cycle}
\rs{6.22,3.45}{6.22,4.21}\pt{6.22,4.21}
\rd{1.78,1.15}{1.78,1.63}\ph{1.78,1.15}
\sd{(3.02,1.21) -- (3.40,1.34) -- (3.40,1.41) -- (3.02,1.28) -- cycle}\sd{(1.27,1.55) -- (3.02,1.21) -- (3.02,1.28) -- (1.27,1.62) -- cycle}\tp{(1.27,1.62) -- (3.02,1.28) -- (3.40,1.41) -- (1.64,1.75) -- cycle}
\rs{2.11,1.62}{2.11,1.87}\pt{2.11,1.87}
\rs{2.43,1.41}{2.43,1.64}\pt{2.43,1.64}
\rd{1.53,1.14}{1.53,1.19}\ph{1.53,1.14}
\rd{1.46,0.74}{1.46,0.87}\ph{1.46,0.74}
\rd{1.61,0.34}{1.61,0.60}\ph{1.61,0.34}
\sd{(1.76,0.49) -- (3.02,0.92) -- (3.02,0.99) -- (1.76,0.55) -- cycle}\sd{(0.00,0.83) -- (1.76,0.49) -- (1.76,0.55) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.76,0.55) -- (3.02,0.99) -- (1.27,1.33) -- cycle}
\rs{0.79,1.05}{0.79,1.21}\pt{0.79,1.21}
\rs{2.11,0.92}{2.11,1.10}\pt{2.11,1.10}
\rs{1.83,0.78}{1.83,0.89}\pt{1.83,0.89}
\rd{4.53,1.86}{4.53,1.88}\ph{4.53,1.86}
\rd{4.37,1.70}{4.37,1.79}\ph{4.37,1.70}
\sd{(4.97,1.53) -- (5.63,1.76) -- (5.63,1.82) -- (4.97,1.60) -- cycle}\sd{(2.73,1.97) -- (4.97,1.53) -- (4.97,1.60) -- (2.73,2.03) -- cycle}\tp{(2.73,2.03) -- (4.97,1.60) -- (5.63,1.82) -- (3.40,2.26) -- cycle}
\rs{4.01,2.05}{4.01,2.16}\pt{4.01,2.16}
\rd{3.38,0.95}{3.38,1.02}\ph{3.38,0.95}
\rd{2.65,0.60}{2.65,0.92}\ph{2.65,0.60}
\rd{3.77,0.78}{3.77,0.88}\ph{3.77,0.78}
\sd{(3.99,0.51) -- (4.97,0.84) -- (4.97,0.91) -- (3.99,0.58) -- cycle}\sd{(1.76,0.95) -- (3.99,0.51) -- (3.99,0.58) -- (1.76,1.01) -- cycle}\tp{(1.76,1.01) -- (3.99,0.58) -- (4.97,0.91) -- (2.73,1.35) -- cycle}
\rs{2.78,1.20}{2.78,1.50}\pt{2.78,1.50}
\rs{3.76,0.98}{3.76,1.17}\pt{3.76,1.17}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.72s = "true", 5.98s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (3.69,-0.87) -- (7.06,0.08) -- (3.37,0.96) -- cycle;
\node at (1.44,-0.55) {$x_1$};
\node at (5.82,-0.50) {$x_2$};
\draw[mid] (1.84,0.52) -- (5.53,-0.35);
\draw[mid] (1.63,-0.38) -- (3.46,0.14);
\draw[mid] (1.42,0.40) -- (3.04,0.02);
\draw[mid] (2.72,-0.07) -- (4.79,-0.56);
\draw[mid] (3.70,0.08) -- (5.24,0.52);
\draw[mid] (2.78,0.79) -- (4.65,0.35);
\draw[mid] (4.15,-0.02) -- (5.68,0.41);
\rd{4.01,2.68}{4.01,3.01}\ph{4.01,2.68}
\sd{(4.65,2.79) -- (5.24,2.95) -- (5.24,3.02) -- (4.65,2.85) -- cycle}\sd{(2.78,3.23) -- (4.65,2.79) -- (4.65,2.85) -- (2.78,3.29) -- cycle}\tp{(2.78,3.29) -- (4.65,2.85) -- (5.24,3.02) -- (3.37,3.46) -- cycle}
\rs{3.93,3.05}{3.93,3.15}\pt{3.93,3.15}
\rs{4.74,2.91}{4.74,3.14}\pt{4.74,3.14}
\rd{2.81,2.17}{2.81,2.58}\ph{2.81,2.17}
\rd{3.35,2.07}{3.35,2.09}\ph{3.35,2.07}
\sd{(3.70,1.89) -- (4.65,2.16) -- (4.65,2.23) -- (3.70,1.96) -- cycle}\sd{(1.84,2.33) -- (3.70,1.89) -- (3.70,1.96) -- (1.84,2.40) -- cycle}\tp{(1.84,2.40) -- (3.70,1.96) -- (4.65,2.23) -- (2.78,2.67) -- cycle}
\rs{3.70,1.93}{3.70,2.36}\pt{3.70,2.36}
\rd{4.75,3.17}{4.75,3.27}\ph{4.75,3.17}
\rd{4.68,3.02}{4.68,3.25}\ph{4.68,3.02}
\sd{(4.15,2.85) -- (5.68,3.28) -- (5.68,3.35) -- (4.15,2.92) -- cycle}\sd{(3.70,2.95) -- (4.15,2.85) -- (4.15,2.92) -- (3.70,3.02) -- cycle}\tp{(3.70,3.02) -- (4.15,2.92) -- (5.68,3.35) -- (5.24,3.45) -- cycle}
\rs{5.49,3.29}{5.49,3.49}\pt{5.49,3.49}
\rs{5.22,3.20}{5.22,3.33}\pt{5.22,3.33}
\rd{4.79,2.89}{4.79,3.55}\ph{4.79,2.89}
\rd{5.46,3.03}{5.46,3.13}\ph{5.46,3.03}
\sd{(5.53,3.02) -- (7.06,3.45) -- (7.06,3.52) -- (5.53,3.09) -- cycle}\sd{(4.15,3.35) -- (5.53,3.02) -- (5.53,3.09) -- (4.15,3.41) -- cycle}\tp{(4.15,3.41) -- (5.53,3.09) -- (7.06,3.52) -- (5.68,3.85) -- cycle}
\rs{6.21,3.30}{6.21,4.06}\pt{6.21,4.06}
\rd{1.94,1.10}{1.94,1.59}\ph{1.94,1.10}
\sd{(3.04,1.14) -- (3.46,1.26) -- (3.46,1.32) -- (3.04,1.20) -- cycle}\sd{(1.42,1.52) -- (3.04,1.14) -- (3.04,1.20) -- (1.42,1.59) -- cycle}\tp{(1.42,1.59) -- (3.04,1.20) -- (3.46,1.32) -- (1.84,1.71) -- cycle}
\rs{2.26,1.56}{2.26,1.82}\pt{2.26,1.82}
\rs{2.51,1.35}{2.51,1.58}\pt{2.51,1.58}
\rd{1.65,1.10}{1.65,1.16}\ph{1.65,1.10}
\rd{1.46,0.70}{1.46,0.83}\ph{1.46,0.70}
\rd{1.50,0.31}{1.50,0.56}\ph{1.50,0.31}
\sd{(1.63,0.44) -- (3.04,0.85) -- (3.04,0.91) -- (1.63,0.51) -- cycle}\sd{(0.00,0.83) -- (1.63,0.44) -- (1.63,0.51) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.63,0.51) -- (3.04,0.91) -- (1.42,1.30) -- cycle}
\rs{0.86,1.03}{0.86,1.19}\pt{0.86,1.19}
\rs{2.12,0.87}{2.12,1.05}\pt{2.12,1.05}
\rs{1.79,0.74}{1.79,0.84}\pt{1.79,0.84}
\rd{4.47,1.75}{4.47,1.78}\ph{4.47,1.75}
\rd{4.27,1.59}{4.27,1.68}\ph{4.27,1.59}
\sd{(4.79,1.41) -- (5.53,1.62) -- (5.53,1.69) -- (4.79,1.48) -- cycle}\sd{(2.72,1.90) -- (4.79,1.41) -- (4.79,1.48) -- (2.72,1.97) -- cycle}\tp{(2.72,1.97) -- (4.79,1.48) -- (5.53,1.69) -- (3.46,2.18) -- cycle}
\rs{4.01,1.95}{4.01,2.07}\pt{4.01,2.07}
\rd{3.25,0.87}{3.25,0.94}\ph{3.25,0.87}
\rd{2.49,0.54}{2.49,0.86}\ph{2.49,0.54}
\rd{3.60,0.69}{3.60,0.79}\ph{3.60,0.69}
\sd{(3.69,0.42) -- (4.79,0.73) -- (4.79,0.80) -- (3.69,0.48) -- cycle}\sd{(1.63,0.91) -- (3.69,0.42) -- (3.69,0.48) -- (1.63,0.97) -- cycle}\tp{(1.63,0.97) -- (3.69,0.48) -- (4.79,0.80) -- (2.72,1.28) -- cycle}
\rs{2.72,1.14}{2.72,1.43}\pt{2.72,1.43}
\rs{3.62,0.89}{3.62,1.08}\pt{3.62,1.08}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.98s = "true", 6.24s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (3.30,-0.97) -- (7.06,-0.12) -- (3.76,0.85) -- cycle;
\node at (1.20,-0.59) {$x_1$};
\node at (5.58,-0.66) {$x_2$};
\draw[mid] (2.05,0.47) -- (5.35,-0.51);
\draw[mid] (1.45,-0.43) -- (3.50,0.04);
\draw[mid] (1.58,0.36) -- (3.03,-0.07);
\draw[mid] (2.67,-0.15) -- (4.52,-0.69);
\draw[mid] (3.71,-0.03) -- (5.42,0.36);
\draw[mid] (3.10,0.70) -- (4.77,0.21);
\draw[mid] (4.11,-0.14) -- (5.82,0.25);
\rd{4.22,2.56}{4.22,2.90}\ph{4.22,2.56}
\sd{(4.77,2.65) -- (5.42,2.80) -- (5.42,2.87) -- (4.77,2.72) -- cycle}\sd{(3.10,3.14) -- (4.77,2.65) -- (4.77,2.72) -- (3.10,3.21) -- cycle}\tp{(3.10,3.21) -- (4.77,2.72) -- (5.42,2.87) -- (3.76,3.36) -- cycle}
\rs{4.15,2.93}{4.15,3.04}\pt{4.15,3.04}
\rs{4.89,2.77}{4.89,3.00}\pt{4.89,3.00}
\rd{3.10,2.09}{3.10,2.50}\ph{3.10,2.09}
\rd{3.44,1.98}{3.44,1.99}\ph{3.44,1.98}
\sd{(3.71,1.78) -- (4.77,2.02) -- (4.77,2.09) -- (3.71,1.85) -- cycle}\sd{(2.05,2.28) -- (3.71,1.78) -- (3.71,1.85) -- (2.05,2.34) -- cycle}\tp{(2.05,2.34) -- (3.71,1.85) -- (4.77,2.09) -- (3.10,2.58) -- cycle}
\rs{3.72,1.83}{3.72,2.25}\pt{3.72,2.25}
\rd{4.88,3.03}{4.88,3.14}\ph{4.88,3.03}
\rd{4.80,2.89}{4.80,3.12}\ph{4.80,2.89}
\sd{(4.11,2.73) -- (5.82,3.12) -- (5.82,3.19) -- (4.11,2.80) -- cycle}\sd{(3.71,2.85) -- (4.11,2.73) -- (4.11,2.80) -- (3.71,2.91) -- cycle}\tp{(3.71,2.91) -- (4.11,2.80) -- (5.82,3.19) -- (5.42,3.30) -- cycle}
\rs{5.62,3.13}{5.62,3.33}\pt{5.62,3.33}
\rs{5.31,3.05}{5.31,3.18}\pt{5.31,3.18}
\rd{4.82,2.76}{4.82,3.41}\ph{4.82,2.76}
\rd{5.31,2.87}{5.31,2.98}\ph{5.31,2.87}
\sd{(5.35,2.86) -- (7.06,3.25) -- (7.06,3.32) -- (5.35,2.93) -- cycle}\sd{(4.11,3.23) -- (5.35,2.86) -- (5.35,2.93) -- (4.11,3.30) -- cycle}\tp{(4.11,3.30) -- (5.35,2.93) -- (7.06,3.32) -- (5.82,3.68) -- cycle}
\rs{6.13,3.13}{6.13,3.89}\pt{6.13,3.89}
\rd{2.11,1.04}{2.11,1.53}\ph{2.11,1.04}
\sd{(3.03,1.05) -- (3.50,1.16) -- (3.50,1.22) -- (3.03,1.12) -- cycle}\sd{(1.58,1.48) -- (3.03,1.05) -- (3.03,1.12) -- (1.58,1.54) -- cycle}\tp{(1.58,1.54) -- (3.03,1.12) -- (3.50,1.22) -- (2.05,1.65) -- cycle}
\rs{2.42,1.50}{2.42,1.75}\pt{2.42,1.75}
\rs{2.58,1.27}{2.58,1.51}\pt{2.58,1.51}
\rd{1.76,1.05}{1.76,1.11}\ph{1.76,1.05}
\rd{1.44,0.66}{1.44,0.79}\ph{1.44,0.66}
\rd{1.37,0.26}{1.37,0.52}\ph{1.37,0.26}
\sd{(1.45,0.40) -- (3.03,0.76) -- (3.03,0.83) -- (1.45,0.47) -- cycle}\sd{(0.00,0.83) -- (1.45,0.40) -- (1.45,0.47) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.45,0.47) -- (3.03,0.83) -- (1.58,1.25) -- cycle}
\rs{0.92,1.00}{0.92,1.16}\pt{0.92,1.16}
\rs{2.11,0.81}{2.11,0.99}\pt{2.11,0.99}
\rs{1.73,0.69}{1.73,0.79}\pt{1.73,0.79}
\rd{4.34,1.62}{4.34,1.65}\ph{4.34,1.62}
\rd{4.11,1.47}{4.11,1.56}\ph{4.11,1.47}
\sd{(4.52,1.28) -- (5.35,1.47) -- (5.35,1.53) -- (4.52,1.35) -- cycle}\sd{(2.67,1.82) -- (4.52,1.28) -- (4.52,1.35) -- (2.67,1.89) -- cycle}\tp{(2.67,1.89) -- (4.52,1.35) -- (5.35,1.53) -- (3.50,2.08) -- cycle}
\rs{3.96,1.84}{3.96,1.95}\pt{3.96,1.95}
\rd{3.07,0.78}{3.07,0.85}\ph{3.07,0.78}
\rd{2.28,0.47}{2.28,0.79}\ph{2.28,0.47}
\rd{3.35,0.59}{3.35,0.69}\ph{3.35,0.59}
\sd{(3.30,0.32) -- (4.52,0.59) -- (4.52,0.66) -- (3.30,0.38) -- cycle}\sd{(1.45,0.86) -- (3.30,0.32) -- (3.30,0.38) -- (1.45,0.93) -- cycle}\tp{(1.45,0.93) -- (3.30,0.38) -- (4.52,0.66) -- (2.67,1.21) -- cycle}
\rs{2.63,1.06}{2.63,1.36}\pt{2.63,1.36}
\rs{3.41,0.79}{3.41,0.98}\pt{3.41,0.98}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.24s = "true", 6.5s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (2.84,-1.06) -- (6.96,-0.33) -- (4.11,0.74) -- cycle;
\node at (0.93,-0.62) {$x_1$};
\node at (5.24,-0.82) {$x_2$};
\draw[mid] (2.24,0.40) -- (5.09,-0.66);
\draw[mid] (1.25,-0.47) -- (3.49,-0.07);
\draw[mid] (1.73,0.31) -- (2.98,-0.16);
\draw[mid] (2.59,-0.23) -- (4.18,-0.82);
\draw[mid] (3.68,-0.14) -- (5.55,0.20);
\draw[mid] (3.39,0.61) -- (4.83,0.07);
\draw[mid] (4.02,-0.26) -- (5.89,0.07);
\rd{4.38,2.43}{4.38,2.77}\ph{4.38,2.43}
\sd{(4.83,2.51) -- (5.55,2.64) -- (5.55,2.70) -- (4.83,2.57) -- cycle}\sd{(3.39,3.04) -- (4.83,2.51) -- (4.83,2.57) -- (3.39,3.11) -- cycle}\tp{(3.39,3.11) -- (4.83,2.57) -- (5.55,2.70) -- (4.11,3.24) -- cycle}
\rs{4.33,2.81}{4.33,2.91}\pt{4.33,2.91}
\rs{5.00,2.63}{5.00,2.85}\pt{5.00,2.85}
\rd{3.37,1.99}{3.37,2.40}\ph{3.37,1.99}
\rd{3.48,1.87}{3.48,1.88}\ph{3.48,1.87}
\sd{(3.68,1.67) -- (4.83,1.88) -- (4.83,1.95) -- (3.68,1.74) -- cycle}\sd{(2.24,2.21) -- (3.68,1.67) -- (3.68,1.74) -- (2.24,2.28) -- cycle}\tp{(2.24,2.28) -- (3.68,1.74) -- (4.83,1.95) -- (3.39,2.49) -- cycle}
\rs{3.68,1.72}{3.68,2.14}\pt{3.68,2.14}
\rd{4.95,2.89}{4.95,2.99}\ph{4.95,2.89}
\rd{4.86,2.74}{4.86,2.97}\ph{4.86,2.74}
\sd{(4.02,2.61) -- (5.89,2.94) -- (5.89,3.01) -- (4.02,2.68) -- cycle}\sd{(3.68,2.74) -- (4.02,2.61) -- (4.02,2.68) -- (3.68,2.80) -- cycle}\tp{(3.68,2.80) -- (4.02,2.68) -- (5.89,3.01) -- (5.55,3.14) -- cycle}
\rs{5.68,2.96}{5.68,3.16}\pt{5.68,3.16}
\rs{5.34,2.89}{5.34,3.02}\pt{5.34,3.02}
\rd{4.79,2.61}{4.79,3.27}\ph{4.79,2.61}
\rd{5.09,2.72}{5.09,2.82}\ph{5.09,2.72}
\sd{(5.09,2.71) -- (6.96,3.04) -- (6.96,3.11) -- (5.09,2.77) -- cycle}\sd{(4.02,3.11) -- (5.09,2.71) -- (5.09,2.77) -- (4.02,3.17) -- cycle}\tp{(4.02,3.17) -- (5.09,2.77) -- (6.96,3.11) -- (5.89,3.51) -- cycle}
\rs{5.97,2.95}{5.97,3.71}\pt{5.97,3.71}
\rd{2.27,0.98}{2.27,1.46}\ph{2.27,0.98}
\sd{(2.98,0.96) -- (3.49,1.05) -- (3.49,1.12) -- (2.98,1.03) -- cycle}\sd{(1.73,1.43) -- (2.98,0.96) -- (2.98,1.03) -- (1.73,1.50) -- cycle}\tp{(1.73,1.50) -- (2.98,1.03) -- (3.49,1.12) -- (2.24,1.59) -- cycle}
\rs{2.56,1.42}{2.56,1.68}\pt{2.56,1.68}
\rs{2.62,1.20}{2.62,1.43}\pt{2.62,1.43}
\rd{1.86,1.00}{1.86,1.05}\ph{1.86,1.00}
\rd{1.39,0.62}{1.39,0.75}\ph{1.39,0.62}
\rd{1.20,0.23}{1.20,0.48}\ph{1.20,0.23}
\sd{(1.25,0.36) -- (2.98,0.67) -- (2.98,0.74) -- (1.25,0.43) -- cycle}\sd{(0.00,0.83) -- (1.25,0.36) -- (1.25,0.43) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.25,0.43) -- (2.98,0.74) -- (1.73,1.21) -- cycle}
\rs{0.98,0.97}{0.98,1.13}\pt{0.98,1.13}
\rs{2.07,0.75}{2.07,0.93}\pt{2.07,0.93}
\rs{1.64,0.64}{1.64,0.74}\pt{1.64,0.74}
\rd{4.15,1.50}{4.15,1.52}\ph{4.15,1.50}
\rd{3.88,1.35}{3.88,1.44}\ph{3.88,1.35}
\sd{(4.18,1.15) -- (5.09,1.31) -- (5.09,1.38) -- (4.18,1.22) -- cycle}\sd{(2.59,1.74) -- (4.18,1.15) -- (4.18,1.22) -- (2.59,1.81) -- cycle}\tp{(2.59,1.81) -- (4.18,1.22) -- (5.09,1.38) -- (3.49,1.97) -- cycle}
\rs{3.86,1.72}{3.86,1.84}\pt{3.86,1.84}
\rd{2.84,0.69}{2.84,0.76}\ph{2.84,0.69}
\rd{2.02,0.41}{2.02,0.73}\ph{2.02,0.41}
\rd{3.04,0.49}{3.04,0.59}\ph{3.04,0.49}
\sd{(2.84,0.22) -- (4.18,0.46) -- (4.18,0.53) -- (2.84,0.29) -- cycle}\sd{(1.25,0.82) -- (2.84,0.22) -- (2.84,0.29) -- (1.25,0.89) -- cycle}\tp{(1.25,0.89) -- (2.84,0.29) -- (4.18,0.53) -- (2.59,1.13) -- cycle}
\rs{2.49,0.98}{2.49,1.28}\pt{2.49,1.28}
\rs{3.15,0.69}{3.15,0.88}\pt{3.15,0.88}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.5s = "true", 6.76s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (2.38,-1.14) -- (6.78,-0.52) -- (4.40,0.61) -- cycle;
\node at (0.66,-0.64) {$x_1$};
\node at (4.86,-0.97) {$x_2$};
\draw[mid] (2.40,0.34) -- (4.77,-0.80);
\draw[mid] (1.05,-0.50) -- (3.44,-0.17);
\draw[mid] (1.85,0.26) -- (2.89,-0.24);
\draw[mid] (2.48,-0.30) -- (3.81,-0.94);
\draw[mid] (3.60,-0.24) -- (5.60,0.04);
\draw[mid] (3.63,0.51) -- (4.83,-0.07);
\draw[mid] (3.88,-0.38) -- (5.88,-0.10);
\rd{4.48,2.31}{4.48,2.64}\ph{4.48,2.31}
\sd{(4.83,2.37) -- (5.60,2.48) -- (5.60,2.54) -- (4.83,2.44) -- cycle}\sd{(3.63,2.94) -- (4.83,2.37) -- (4.83,2.44) -- (3.63,3.01) -- cycle}\tp{(3.63,3.01) -- (4.83,2.44) -- (5.60,2.54) -- (4.40,3.12) -- cycle}
\rs{4.45,2.68}{4.45,2.79}\pt{4.45,2.79}
\rs{5.03,2.48}{5.03,2.71}\pt{5.03,2.71}
\rd{3.59,1.89}{3.59,2.30}\ph{3.59,1.89}
\rd{3.47,1.77}{3.47,1.79}\ph{3.47,1.77}
\sd{(3.60,1.57) -- (4.83,1.74) -- (4.83,1.81) -- (3.60,1.64) -- cycle}\sd{(2.40,2.15) -- (3.60,1.57) -- (3.60,1.64) -- (2.40,2.21) -- cycle}\tp{(2.40,2.21) -- (3.60,1.64) -- (4.83,1.81) -- (3.63,2.39) -- cycle}
\rs{3.61,1.61}{3.61,2.04}\pt{3.61,2.04}
\rd{4.95,2.75}{4.95,2.85}\ph{4.95,2.75}
\rd{4.86,2.60}{4.86,2.84}\ph{4.86,2.60}
\sd{(3.88,2.50) -- (5.88,2.77) -- (5.88,2.84) -- (3.88,2.56) -- cycle}\sd{(3.60,2.63) -- (3.88,2.50) -- (3.88,2.56) -- (3.60,2.70) -- cycle}\tp{(3.60,2.70) -- (3.88,2.56) -- (5.88,2.84) -- (5.60,2.98) -- cycle}
\rs{5.67,2.80}{5.67,3.00}\pt{5.67,3.00}
\rs{5.30,2.73}{5.30,2.87}\pt{5.30,2.87}
\rd{4.71,2.48}{4.71,3.14}\ph{4.71,2.48}
\rd{4.81,2.58}{4.81,2.68}\ph{4.81,2.58}
\sd{(4.77,2.57) -- (6.78,2.85) -- (6.78,2.91) -- (4.77,2.63) -- cycle}\sd{(3.88,2.99) -- (4.77,2.57) -- (4.77,2.63) -- (3.88,3.06) -- cycle}\tp{(3.88,3.06) -- (4.77,2.63) -- (6.78,2.91) -- (5.88,3.34) -- cycle}
\rs{5.74,2.78}{5.74,3.54}\pt{5.74,3.54}
\rd{2.39,0.91}{2.39,1.40}\ph{2.39,0.91}
\sd{(2.89,0.88) -- (3.44,0.95) -- (3.44,1.02) -- (2.89,0.94) -- cycle}\sd{(1.85,1.38) -- (2.89,0.88) -- (2.89,0.94) -- (1.85,1.44) -- cycle}\tp{(1.85,1.44) -- (2.89,0.94) -- (3.44,1.02) -- (2.40,1.52) -- cycle}
\rs{2.66,1.35}{2.66,1.60}\pt{2.66,1.60}
\rs{2.62,1.12}{2.62,1.35}\pt{2.62,1.35}
\rd{1.93,0.94}{1.93,1.00}\ph{1.93,0.94}
\rd{1.34,0.58}{1.34,0.71}\ph{1.34,0.58}
\rd{1.03,0.19}{1.03,0.45}\ph{1.03,0.19}
\sd{(1.05,0.33) -- (2.89,0.59) -- (2.89,0.65) -- (1.05,0.39) -- cycle}\sd{(0.00,0.83) -- (1.05,0.33) -- (1.05,0.39) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (1.05,0.39) -- (2.89,0.65) -- (1.85,1.15) -- cycle}
\rs{1.02,0.95}{1.02,1.10}\pt{1.02,1.10}
\rs{2.01,0.69}{2.01,0.87}\pt{2.01,0.87}
\rs{1.53,0.59}{1.53,0.70}\pt{1.53,0.70}
\rd{3.92,1.38}{3.92,1.41}\ph{3.92,1.38}
\rd{3.62,1.25}{3.62,1.34}\ph{3.62,1.25}
\sd{(3.81,1.03) -- (4.77,1.17) -- (4.77,1.24) -- (3.81,1.10) -- cycle}\sd{(2.48,1.67) -- (3.81,1.03) -- (3.81,1.10) -- (2.48,1.74) -- cycle}\tp{(2.48,1.74) -- (3.81,1.10) -- (4.77,1.24) -- (3.44,1.87) -- cycle}
\rs{3.72,1.61}{3.72,1.73}\pt{3.72,1.73}
\rd{1.76,0.36}{1.76,0.67}\ph{1.76,0.36}
\rd{2.58,0.61}{2.58,0.68}\ph{2.58,0.61}
\rd{2.72,0.41}{2.72,0.51}\ph{2.72,0.41}
\sd{(2.38,0.15) -- (3.81,0.35) -- (3.81,0.42) -- (2.38,0.22) -- cycle}\sd{(1.05,0.79) -- (2.38,0.15) -- (2.38,0.22) -- (1.05,0.86) -- cycle}\tp{(1.05,0.86) -- (2.38,0.22) -- (3.81,0.42) -- (2.48,1.06) -- cycle}
\rs{2.33,0.91}{2.33,1.21}\pt{2.33,1.21}
\rs{2.86,0.60}{2.86,0.80}\pt{2.86,0.80}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.76s = "true", 7.02s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (1.96,-1.19) -- (6.56,-0.68) -- (4.60,0.51) -- cycle;
\node at (0.43,-0.66) {$x_1$};
\node at (4.49,-1.08) {$x_2$};
\draw[mid] (2.51,0.28) -- (4.46,-0.91);
\draw[mid] (0.86,-0.52) -- (3.37,-0.25);
\draw[mid] (1.93,0.21) -- (2.79,-0.31);
\draw[mid] (2.36,-0.36) -- (3.45,-1.03);
\draw[mid] (3.50,-0.33) -- (5.59,-0.09);
\draw[mid] (3.80,0.42) -- (4.78,-0.18);
\draw[mid] (3.73,-0.47) -- (5.82,-0.24);
\rd{4.52,2.20}{4.52,2.53}\ph{4.52,2.20}
\sd{(4.78,2.25) -- (5.59,2.34) -- (5.59,2.41) -- (4.78,2.32) -- cycle}\sd{(3.80,2.85) -- (4.78,2.25) -- (4.78,2.32) -- (3.80,2.92) -- cycle}\tp{(3.80,2.92) -- (4.78,2.32) -- (5.59,2.41) -- (4.60,3.01) -- cycle}
\rs{4.50,2.57}{4.50,2.68}\pt{4.50,2.68}
\rs{5.01,2.36}{5.01,2.59}\pt{5.01,2.59}
\rd{3.74,1.80}{3.74,2.21}\ph{3.74,1.80}
\rd{3.44,1.69}{3.44,1.70}\ph{3.44,1.69}
\sd{(3.50,1.48) -- (4.78,1.63) -- (4.78,1.69) -- (3.50,1.55) -- cycle}\sd{(2.51,2.09) -- (3.50,1.48) -- (3.50,1.55) -- (2.51,2.15) -- cycle}\tp{(2.51,2.15) -- (3.50,1.55) -- (4.78,1.69) -- (3.80,2.30) -- cycle}
\rs{3.51,1.53}{3.51,1.95}\pt{3.51,1.95}
\rd{4.91,2.63}{4.91,2.73}\ph{4.91,2.63}
\rd{4.82,2.49}{4.82,2.72}\ph{4.82,2.49}
\sd{(3.73,2.40) -- (5.82,2.63) -- (5.82,2.70) -- (3.73,2.47) -- cycle}\sd{(3.50,2.55) -- (3.73,2.40) -- (3.73,2.47) -- (3.50,2.61) -- cycle}\tp{(3.50,2.61) -- (3.73,2.47) -- (5.82,2.70) -- (5.59,2.84) -- cycle}
\rs{5.61,2.67}{5.61,2.87}\pt{5.61,2.87}
\rs{5.22,2.61}{5.22,2.74}\pt{5.22,2.74}
\rd{4.59,2.36}{4.59,3.02}\ph{4.59,2.36}
\rd{4.53,2.46}{4.53,2.57}\ph{4.53,2.46}
\sd{(4.46,2.46) -- (6.56,2.69) -- (6.56,2.75) -- (4.46,2.52) -- cycle}\sd{(3.73,2.90) -- (4.46,2.46) -- (4.46,2.52) -- (3.73,2.97) -- cycle}\tp{(3.73,2.97) -- (4.46,2.52) -- (6.56,2.75) -- (5.82,3.20) -- cycle}
\rs{5.49,2.64}{5.49,3.41}\pt{5.49,3.41}
\rd{2.46,0.85}{2.46,1.34}\ph{2.46,0.85}
\sd{(2.79,0.81) -- (3.37,0.87) -- (3.37,0.94) -- (2.79,0.87) -- cycle}\sd{(1.93,1.33) -- (2.79,0.81) -- (2.79,0.87) -- (1.93,1.40) -- cycle}\tp{(1.93,1.40) -- (2.79,0.87) -- (3.37,0.94) -- (2.51,1.46) -- cycle}
\rs{2.72,1.28}{2.72,1.54}\pt{2.72,1.54}
\rs{2.60,1.06}{2.60,1.29}\pt{2.60,1.29}
\rd{1.97,0.89}{1.97,0.95}\ph{1.97,0.89}
\rd{1.28,0.55}{1.28,0.68}\ph{1.28,0.55}
\rd{0.88,0.17}{0.88,0.42}\ph{0.88,0.17}
\sd{(0.86,0.30) -- (2.79,0.52) -- (2.79,0.58) -- (0.86,0.37) -- cycle}\sd{(0.00,0.83) -- (0.86,0.30) -- (0.86,0.37) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (0.86,0.37) -- (2.79,0.58) -- (1.93,1.11) -- cycle}
\rs{1.04,0.92}{1.04,1.08}\pt{1.04,1.08}
\rs{1.94,0.64}{1.94,0.82}\pt{1.94,0.82}
\rs{1.43,0.56}{1.43,0.66}\pt{1.43,0.66}
\rd{3.69,1.29}{3.69,1.32}\ph{3.69,1.29}
\rd{3.36,1.16}{3.36,1.25}\ph{3.36,1.16}
\sd{(3.45,0.95) -- (4.46,1.06) -- (4.46,1.13) -- (3.45,1.01) -- cycle}\sd{(2.36,1.61) -- (3.45,0.95) -- (3.45,1.01) -- (2.36,1.68) -- cycle}\tp{(2.36,1.68) -- (3.45,1.01) -- (4.46,1.13) -- (3.37,1.79) -- cycle}
\rs{3.56,1.53}{3.56,1.64}\pt{3.56,1.64}
\rd{1.52,0.32}{1.52,0.63}\ph{1.52,0.32}
\rd{2.34,0.55}{2.34,0.62}\ph{2.34,0.55}
\rd{2.41,0.35}{2.41,0.45}\ph{2.41,0.35}
\sd{(1.96,0.10) -- (3.45,0.26) -- (3.45,0.33) -- (1.96,0.17) -- cycle}\sd{(0.86,0.77) -- (1.96,0.10) -- (1.96,0.17) -- (0.86,0.83) -- cycle}\tp{(0.86,0.83) -- (1.96,0.17) -- (3.45,0.33) -- (2.36,1.00) -- cycle}
\rs{2.17,0.86}{2.17,1.16}\pt{2.17,1.16}
\rs{2.59,0.54}{2.59,0.73}\pt{2.59,0.73}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.02s = "true", 7.28s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (1.66,-1.22) -- (6.38,-0.79) -- (4.72,0.43) -- cycle;
\node at (0.26,-0.66) {$x_1$};
\node at (4.22,-1.15) {$x_2$};
\draw[mid] (2.57,0.23) -- (4.23,-0.99);
\draw[mid] (0.73,-0.54) -- (3.30,-0.30);
\draw[mid] (1.98,0.18) -- (2.71,-0.36);
\draw[mid] (2.26,-0.40) -- (3.19,-1.08);
\draw[mid] (3.41,-0.38) -- (5.55,-0.19);
\draw[mid] (3.89,0.35) -- (4.73,-0.26);
\draw[mid] (3.61,-0.53) -- (5.75,-0.33);
\rd{4.52,2.12}{4.52,2.46}\ph{4.52,2.12}
\sd{(4.73,2.17) -- (5.55,2.25) -- (5.55,2.32) -- (4.73,2.24) -- cycle}\sd{(3.89,2.79) -- (4.73,2.17) -- (4.73,2.24) -- (3.89,2.86) -- cycle}\tp{(3.89,2.86) -- (4.73,2.24) -- (5.55,2.32) -- (4.72,2.93) -- cycle}
\rs{4.52,2.50}{4.52,2.60}\pt{4.52,2.60}
\rs{4.98,2.28}{4.98,2.51}\pt{4.98,2.51}
\rd{3.82,1.74}{3.82,2.15}\ph{3.82,1.74}
\rd{3.40,1.63}{3.40,1.65}\ph{3.40,1.63}
\sd{(3.41,1.43) -- (4.73,1.55) -- (4.73,1.62) -- (3.41,1.50) -- cycle}\sd{(2.57,2.04) -- (3.41,1.43) -- (3.41,1.50) -- (2.57,2.11) -- cycle}\tp{(2.57,2.11) -- (3.41,1.50) -- (4.73,1.62) -- (3.89,2.23) -- cycle}
\rs{3.42,1.47}{3.42,1.89}\pt{3.42,1.89}
\rd{4.76,2.41}{4.76,2.64}\ph{4.76,2.41}
\rd{4.86,2.55}{4.86,2.65}\ph{4.86,2.55}
\sd{(3.61,2.34) -- (5.75,2.54) -- (5.75,2.61) -- (3.61,2.41) -- cycle}\sd{(3.41,2.49) -- (3.61,2.34) -- (3.61,2.41) -- (3.41,2.56) -- cycle}\tp{(3.41,2.56) -- (3.61,2.41) -- (5.75,2.61) -- (5.55,2.75) -- cycle}
\rs{5.54,2.57}{5.54,2.77}\pt{5.54,2.77}
\rs{5.13,2.52}{5.13,2.66}\pt{5.13,2.66}
\rd{4.49,2.29}{4.49,2.95}\ph{4.49,2.29}
\rd{4.31,2.39}{4.31,2.49}\ph{4.31,2.39}
\sd{(4.23,2.38) -- (6.38,2.58) -- (6.38,2.65) -- (4.23,2.45) -- cycle}\sd{(3.61,2.84) -- (4.23,2.38) -- (4.23,2.45) -- (3.61,2.91) -- cycle}\tp{(3.61,2.91) -- (4.23,2.45) -- (6.38,2.65) -- (5.75,3.10) -- cycle}
\rs{5.29,2.55}{5.29,3.32}\pt{5.29,3.32}
\rd{2.51,0.81}{2.51,1.30}\ph{2.51,0.81}
\sd{(2.71,0.76) -- (3.30,0.82) -- (3.30,0.88) -- (2.71,0.83) -- cycle}\sd{(1.98,1.30) -- (2.71,0.76) -- (2.71,0.83) -- (1.98,1.37) -- cycle}\tp{(1.98,1.37) -- (2.71,0.83) -- (3.30,0.88) -- (2.57,1.42) -- cycle}
\rs{2.75,1.24}{2.75,1.49}\pt{2.75,1.49}
\rs{2.57,1.02}{2.57,1.25}\pt{2.57,1.25}
\rd{1.99,0.86}{1.99,0.92}\ph{1.99,0.86}
\rd{1.23,0.53}{1.23,0.66}\ph{1.23,0.53}
\rd{0.77,0.16}{0.77,0.41}\ph{0.77,0.16}
\sd{(0.73,0.29) -- (2.71,0.47) -- (2.71,0.54) -- (0.73,0.36) -- cycle}\sd{(0.00,0.83) -- (0.73,0.29) -- (0.73,0.36) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (0.73,0.36) -- (2.71,0.54) -- (1.98,1.08) -- cycle}
\rs{1.06,0.90}{1.06,1.06}\pt{1.06,1.06}
\rs{1.88,0.61}{1.88,0.79}\pt{1.88,0.79}
\rs{1.35,0.53}{1.35,0.64}\pt{1.35,0.64}
\rd{3.51,1.23}{3.51,1.26}\ph{3.51,1.23}
\rd{3.17,1.11}{3.17,1.20}\ph{3.17,1.11}
\sd{(3.19,0.89) -- (4.23,0.99) -- (4.23,1.05) -- (3.19,0.96) -- cycle}\sd{(2.26,1.57) -- (3.19,0.89) -- (3.19,0.96) -- (2.26,1.64) -- cycle}\tp{(2.26,1.64) -- (3.19,0.96) -- (4.23,1.05) -- (3.30,1.74) -- cycle}
\rs{3.43,1.47}{3.43,1.58}\pt{3.43,1.58}
\rd{1.34,0.29}{1.34,0.61}\ph{1.34,0.29}
\rd{2.17,0.51}{2.17,0.59}\ph{2.17,0.51}
\rd{2.19,0.31}{2.19,0.41}\ph{2.19,0.31}
\sd{(1.66,0.07) -- (3.19,0.21) -- (3.19,0.28) -- (1.66,0.14) -- cycle}\sd{(0.73,0.75) -- (1.66,0.07) -- (1.66,0.14) -- (0.73,0.82) -- cycle}\tp{(0.73,0.82) -- (1.66,0.14) -- (3.19,0.28) -- (2.26,0.96) -- cycle}
\rs{2.06,0.82}{2.06,1.12}\pt{2.06,1.12}
\rs{2.39,0.50}{2.39,0.69}\pt{2.39,0.69}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.28s = "true", 10.68s = "false", 10.68s = "false", repeats}}}]
\draw[mid, thick] (0.00,0.00) -- (1.55,-1.23) -- (6.30,-0.83) -- (4.76,0.40) -- cycle;
\node at (0.20,-0.66) {$x_1$};
\node at (4.11,-1.18) {$x_2$};
\draw[mid] (2.59,0.22) -- (4.14,-1.01);
\draw[mid] (0.68,-0.54) -- (3.27,-0.32);
\draw[mid] (2.00,0.17) -- (2.68,-0.37);
\draw[mid] (2.23,-0.41) -- (3.09,-1.10);
\draw[mid] (3.37,-0.40) -- (5.54,-0.22);
\draw[mid] (3.92,0.33) -- (4.70,-0.29);
\draw[mid] (3.56,-0.55) -- (5.72,-0.37);
\rd{4.52,2.10}{4.52,2.43}\ph{4.52,2.10}
\sd{(4.70,2.15) -- (5.54,2.22) -- (5.54,2.28) -- (4.70,2.21) -- cycle}\sd{(3.92,2.77) -- (4.70,2.15) -- (4.70,2.21) -- (3.92,2.83) -- cycle}\tp{(3.92,2.83) -- (4.70,2.21) -- (5.54,2.28) -- (4.76,2.90) -- cycle}
\rs{4.52,2.47}{4.52,2.58}\pt{4.52,2.58}
\rs{4.96,2.25}{4.96,2.48}\pt{4.96,2.48}
\rd{3.85,1.71}{3.85,2.13}\ph{3.85,1.71}
\rd{3.38,1.61}{3.38,1.62}\ph{3.38,1.61}
\sd{(3.37,1.41) -- (4.70,1.52) -- (4.70,1.59) -- (3.37,1.47) -- cycle}\sd{(2.59,2.03) -- (3.37,1.41) -- (3.37,1.47) -- (2.59,2.10) -- cycle}\tp{(2.59,2.10) -- (3.37,1.47) -- (4.70,1.59) -- (3.92,2.21) -- cycle}
\rs{3.39,1.45}{3.39,1.87}\pt{3.39,1.87}
\rd{4.73,2.38}{4.73,2.61}\ph{4.73,2.38}
\rd{4.83,2.52}{4.83,2.62}\ph{4.83,2.52}
\sd{(3.56,2.32) -- (5.72,2.50) -- (5.72,2.57) -- (3.56,2.39) -- cycle}\sd{(3.37,2.47) -- (3.56,2.32) -- (3.56,2.39) -- (3.37,2.54) -- cycle}\tp{(3.37,2.54) -- (3.56,2.39) -- (5.72,2.57) -- (5.54,2.72) -- cycle}
\rs{5.51,2.54}{5.51,2.74}\pt{5.51,2.74}
\rs{5.10,2.49}{5.10,2.62}\pt{5.10,2.62}
\rd{4.44,2.26}{4.44,2.92}\ph{4.44,2.26}
\rd{4.23,2.36}{4.23,2.47}\ph{4.23,2.36}
\sd{(4.14,2.36) -- (6.30,2.54) -- (6.30,2.61) -- (4.14,2.42) -- cycle}\sd{(3.56,2.82) -- (4.14,2.36) -- (4.14,2.42) -- (3.56,2.89) -- cycle}\tp{(3.56,2.89) -- (4.14,2.42) -- (6.30,2.61) -- (5.72,3.07) -- cycle}
\rs{5.21,2.52}{5.21,3.28}\pt{5.21,3.28}
\rd{2.52,0.80}{2.52,1.28}\ph{2.52,0.80}
\sd{(2.68,0.74) -- (3.27,0.79) -- (3.27,0.86) -- (2.68,0.81) -- cycle}\sd{(2.00,1.29) -- (2.68,0.74) -- (2.68,0.81) -- (2.00,1.35) -- cycle}\tp{(2.00,1.35) -- (2.68,0.81) -- (3.27,0.86) -- (2.59,1.40) -- cycle}
\rs{2.75,1.22}{2.75,1.48}\pt{2.75,1.48}
\rs{2.56,1.00}{2.56,1.23}\pt{2.56,1.23}
\rd{1.99,0.85}{1.99,0.91}\ph{1.99,0.85}
\rd{1.21,0.52}{1.21,0.65}\ph{1.21,0.52}
\rd{0.73,0.15}{0.73,0.41}\ph{0.73,0.15}
\sd{(0.68,0.29) -- (2.68,0.45) -- (2.68,0.52) -- (0.68,0.35) -- cycle}\sd{(0.00,0.83) -- (0.68,0.29) -- (0.68,0.35) -- (0.00,0.90) -- cycle}\tp{(0.00,0.90) -- (0.68,0.35) -- (2.68,0.52) -- (2.00,1.06) -- cycle}
\rs{1.06,0.90}{1.06,1.06}\pt{1.06,1.06}
\rs{1.86,0.60}{1.86,0.78}\pt{1.86,0.78}
\rs{1.32,0.52}{1.32,0.63}\pt{1.32,0.63}
\rd{3.44,1.21}{3.44,1.23}\ph{3.44,1.21}
\rd{3.09,1.09}{3.09,1.18}\ph{3.09,1.09}
\sd{(3.09,0.87) -- (4.14,0.96) -- (4.14,1.03) -- (3.09,0.94) -- cycle}\sd{(2.23,1.56) -- (3.09,0.87) -- (3.09,0.94) -- (2.23,1.63) -- cycle}\tp{(2.23,1.63) -- (3.09,0.94) -- (4.14,1.03) -- (3.27,1.72) -- cycle}
\rs{3.38,1.45}{3.38,1.56}\pt{3.38,1.56}
\rd{1.28,0.28}{1.28,0.60}\ph{1.28,0.28}
\rd{2.10,0.50}{2.10,0.57}\ph{2.10,0.50}
\rd{2.11,0.30}{2.11,0.40}\ph{2.11,0.30}
\sd{(1.55,0.06) -- (3.09,0.19) -- (3.09,0.26) -- (1.55,0.13) -- cycle}\sd{(0.68,0.75) -- (1.55,0.06) -- (1.55,0.13) -- (0.68,0.82) -- cycle}\tp{(0.68,0.82) -- (1.55,0.13) -- (3.09,0.26) -- (2.23,0.95) -- cycle}
\rs{2.01,0.81}{2.01,1.11}\pt{2.01,1.11}
\rs{2.32,0.48}{2.32,0.67}\pt{2.32,0.67}
\draw[->] (0.00,0.00) -- (0.00,4.14);
\node at (0.00,4.42) {$y$};
\draw (-0.07,1.06) -- (0.00,1.06) node[pos=0, left] {\footnotesize $0.5$};
\draw (-0.07,2.13) -- (0.00,2.13) node[pos=0, left] {\footnotesize $1$};
\draw (-0.07,3.19) -- (0.00,3.19) node[pos=0, left] {\footnotesize $1.5$};
\node[anchor=west] at (-3.4,-2.6) {The prediction is piecewise constant: flat on each rectangle, with jumps at the splits.};
\end{scope}
\node[anchor=west] at (-3.4,-3.15) {\footnotesize red: training points (hollow when below their block), \ blue: the leaf prediction $\hat y$};
\end{tikzpicture}
\end{document}

(No Scaling Needed) A split depends only on the order of a feature’s values, so an increasing transformation leaves the tree unchanged.

Standardizing, taking logs or converting units changes no split, because the same points fall on each side of each threshold. Distance-based methods such as 4.5. k-Nearest Neighbors need scaled features, and a tree does not. Categorical features need no one-hot encoding either. For a regression target, CART sorts the categories by their mean target. It then tries only the splits along that order. This ordering finds the best of all partitions (Breiman et al., 1984). CART handles missing values with surrogate splits, which are backup splits on other features that mimic the primary one.

For an internal node , let be its training error as a leaf and the branch below it. Collapsing raises the error by and removes leaves. The ratio

is the penalty at which the collapsed and uncollapsed trees have equal cost . Weakest-link pruning collapses the node with the smallest , recomputes , and repeats until only the root remains. Breiman et al. (1984) proved that this sequence contains the minimizer of for every . Cross-validation then only has to compare the few trees in the sequence.

Examples

(Easy) First Split for Apartment Rents

Six apartments have floor areas m². Their monthly rents are hundred dollars. A regression tree chooses its first split on area.

(Medium) Gini for a Spam Filter

A node holds emails, spam and legitimate. Split A asks whether the email contains the word “free”. The emails with the word include spam, and the other include spam. Split B asks whether the email has more than three links. Each side has emails, with spam on the “yes” side and on the “no” side.

(Hard) Pruning a Loan-Default Tree

A classification tree for loan applicants has root with children and . Node splits into leaves and . Node splits into node and leaf , and splits into leaves and . The table lists each node’s misclassification count if it were a leaf.

Node
Errors

See Also