uni farm

bootstrap法

bootstrap法

bootstrap法について、考え方と、使い方をまとめておく

方法

抽出対象となる標本データに対して、重複を許してランダムにデータを取り出して(復元抽出)、再標本化(resampling)する手法

標本データで学習すると生じる、真の値からの誤差(バイアス)を小さくするために用いる

  • 例)

リサンプリング数: 3、標本数: 2のとき

X: 1, 2, 3, 4, 5からサンプリングすると

x1: 1, 3
x2: 1, 5
x3: 2, 4

実装

scikit-learn(0.21.3) を用いる

from sklearn import utils

# data
data = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
label = [1, 0, 1, 1, 0, 0]

# サンプル数は4。指定ないとdataの長さの分だけ行う
data_boot, label_boot = utils.resample(data, label, replace=True, n_samples=4, random_state=1)

print('bootstrap sample: %s' % data_boot)
print('bootstrap sample: %s' % label_boot)

# 残ったもの
o = [x for x in data if x not in boot]
print('remained sample: %s' % o)


...
bootstrap sample: [0.6, 0.4, 0.5, 0.1]
bootstrap sample: [0, 1, 0, 0]
remained sample: [0.2, 0.3]

参考

  • 『はじめてのパターン認識』

  • https://scikit-learn.org/stable/modules/generated/sklearn.utils.resample.html

  • https://qiita.com/tjmnmn/items/3aed6fb85f75446f74ca

2023, Built with Gatsby. This site uses Google Analytics.