Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

決定木

回帰木

MM次元の特徴量xRM\boldsymbol{x}\in \mathbb{R}^Mと教師ラベルyyのペアからなるサンプルがNN個あるとする。

回帰木(regression tree)は特徴空間をKK個の領域に区切ったもの

y^i=k=1Kfk(x)\hat{y}_i = \sum^K_{k=1} f_k(x)

ここでfk(x)=wq(x)f_k(x) = w_{q(x)}で、q:RMRq: \mathbb{R}^M \to R

import numpy as np
import matplotlib.pyplot as plt

n = 10
np.random.seed(0)

# class 0
y0 = np.zeros(shape=(n//2, ))
x0 = np.random.normal(loc=(-1, -1), scale=0.8, size=(n//2, 2))

# class 1
y1 = np.ones(shape=(n//2, ))
x1 = np.random.normal(loc=(1, 1), scale=0.8, size=(n//2, 2))

y = np.append(y0, y1)
X = np.append(x0, x1, axis=0)

fig, ax = plt.subplots()
ax.scatter(X[(y == 0), 0], X[(y == 0), 1], label="y = 0")
ax.scatter(X[(y == 1), 0], X[(y == 1), 1], label="y = 1")
ax.legend()
ax.set(xlabel="x1", ylabel="x2")
fig.show()
<Figure size 640x480 with 1 Axes>