決定木

Contents

決定木#

回帰木#

M次元の特徴量xRMと教師ラベルyのペアからなるサンプルがN個あるとする。

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

y^i=k=1Kfk(x)

ここでfk(x)=wq(x)で、$q: \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()
../../_images/6e41b9cc97496516cb5e12777a4b82f8644615f9c63a586ae46ef02d90ac8ea3.png
for x in X[:, 0]:
    x