Skip to content

Instantly share code, notes, and snippets.

@axjack
Created November 27, 2021 05:31
Show Gist options
  • Save axjack/4e684dc279f5af7f2ff1616eef4bfb92 to your computer and use it in GitHub Desktop.
Save axjack/4e684dc279f5af7f2ff1616eef4bfb92 to your computer and use it in GitHub Desktop.
問23.2
# -------------
# 第23章 判別分析
# 問23.2 p.213
# -------------
# データ
LD1 <- c(-0.1,-0.1,0.2,0.4,0.9)
LD2 <- c(0.0,0.2,-0.2,0.9,-0.3)
x1 <- c(1.2,1.4,0.3,6.0,4.6)
x2 <- c(1.4,1.4,0.3,0.7,2.1)
x3 <- c(0.8,0.2,1.6,3.6,9.2)
xL <- c(2.5,-1.1,0,-0.8,1.0)
# 射影後の座標
f <- function(x){
c(LD1 %*% x,LD2 %*% x)
}
# 距離計算
matrix( c(f(x1),f(x2),f(x3),f(xL)), byrow = T, ncol=2 ) |> dist()
@axjack
Copy link
Author

axjack commented Nov 27, 2021

> matrix( c(f(x1),f(x2),f(x3),f(xL)), byrow = T, ncol=2 ) |> dist()
         1        2        3
2 5.952520                  
3 5.411248 7.990025         
4 8.052354 2.100405 9.608517
> 

となるので、新しいサンプルから最も近い重心を持つクラスは、x2すなわちクラスFの群となる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment