LoginSignup
0
0

More than 1 year has passed since last update.

Octave で中心化と標準化

Posted at

Octave で中心化と標準化

元データから平均値を引く(中心化 center),更に標準偏差で割る(標準化 zscore)を行う。

usage:
center(x)
center(x, dim)

z = zscore (x)
z = zscore (x, opt)
z = zscore (x, opt, dim)
[z, mu, sigma] = zscore (…)

opt=0(デフォルト) 不偏分散の平方根, opt=1 不偏ではない分散の平方根 を使う
dim を指定するときには opt を明示的に指定しなければならない

中心化 center()

x = [11, 12, 13, 14, 15]
center(x)
x =

   11   12   13   14   15

ans =

  -2  -1   0   1   2
y = [11, 12, 13, 14, 15; 1, 2, 3, 4, 5; 21, 22, 23, 24, 25]
center(y) # dim = 1
y =

   11   12   13   14   15
    1    2    3    4    5
   21   22   23   24   25

ans =

    0    0    0    0    0
  -10  -10  -10  -10  -10
   10   10   10   10   10
center(y, dim = 2)
ans =

  -2  -1   0   1   2
  -2  -1   0   1   2
  -2  -1   0   1   2

標準化(正規化) zscoer()

format short
zscore(x)
ans =

  -1.2649  -0.6325        0   0.6325   1.2649
zscore(y) # dim = 1
ans =

   0   0   0   0   0
  -1  -1  -1  -1  -1
   1   1   1   1   1
zscore(y, opt=0, dim = 2)
ans =

  -1.2649  -0.6325        0   0.6325   1.2649
  -1.2649  -0.6325        0   0.6325   1.2649
  -1.2649  -0.6325        0   0.6325   1.2649
zscore(y, opt=1, dim = 2)
ans =

  -1.4142  -0.7071        0   0.7071   1.4142
  -1.4142  -0.7071        0   0.7071   1.4142
  -1.4142  -0.7071        0   0.7071   1.4142
[z, mu, sigma] = zscore(y, opt=0, dim = 2)
z =

  -1.2649  -0.6325        0   0.6325   1.2649
  -1.2649  -0.6325        0   0.6325   1.2649
  -1.2649  -0.6325        0   0.6325   1.2649

mu =

   13
    3
   23

sigma =

   1.5811
   1.5811
   1.5811
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0