前言:
微博參與話題 #給你四年時(shí)間你也學(xué)不會(huì)生信#
1、數(shù)據(jù)的中心化
所謂數(shù)據(jù)的中心化是指數(shù)據(jù)集中的各項(xiàng)數(shù)據(jù)減去數(shù)據(jù)集的均值。
例如有數(shù)據(jù)集1, 2, 3, 6, 3,其均值為3,那么中心化之后的數(shù)據(jù)集為1-3,2-3,3-3,6-3,3-3,即:-2,-1,0,3,0
2、數(shù)據(jù)的標(biāo)準(zhǔn)化
所謂數(shù)據(jù)的標(biāo)準(zhǔn)化是指中心化之后的數(shù)據(jù)在除以數(shù)據(jù)集的標(biāo)準(zhǔn)差,即數(shù)據(jù)集中的各項(xiàng)數(shù)據(jù)減去數(shù)據(jù)集的均值再除以數(shù)據(jù)集的標(biāo)準(zhǔn)差。
例如有數(shù)據(jù)集1, 2, 3, 6, 3,其均值為3,其標(biāo)準(zhǔn)差為1.87,那么標(biāo)準(zhǔn)化之后的數(shù)據(jù)集為(1-3)/1.87,(2-3)/1.87,(3-3)/1.87,(6-3)/1.87,(3-3)/1.87,即:-1.069,-0.535,0,1.604,0
數(shù)據(jù)中心化和標(biāo)準(zhǔn)化的意義是一樣的,為了消除量綱對(duì)數(shù)據(jù)結(jié)構(gòu)的影響。
在R語言中可以使用scale方法來對(duì)數(shù)據(jù)進(jìn)行中心化和標(biāo)準(zhǔn)化:
#限定輸出小數(shù)點(diǎn)后數(shù)字的位數(shù)為3位
> options(digits=3)
> data <- c(1, 2, 3, 6, 3)
> scale(data, center=T,scale=F) #數(shù)據(jù)中心化
[,1]
[1,] -2
[2,] -1
[3,] 0
[4,] 3
[5,] 0
attr(,"scaled:center")
[1] 3
> scale(data, center=T,scale=T) #數(shù)據(jù)標(biāo)準(zhǔn)化
[,1]
[1,] -1.069
[2,] -0.535
[3,] 0.000
[4,] 1.604
[5,] 0.000
attr(,"scaled:center")
[1] 3
attr(,"scaled:scale")
[1] 1.87
scale方法中的兩個(gè)參數(shù)center和scale的解釋:
1)center和scale默認(rèn)為真,即T或者TRUE
2)center為真表示數(shù)據(jù)中心化
3)scale為真表示數(shù)據(jù)標(biāo)準(zhǔn)化
參考資料:R語言的scale函數(shù)