ISLR系列:(4.3)模型選擇 PCR & PLS


Linear Model Selection and Regularization

此博文是 An Introduction to Statistical Learning with Applications in R 的系列讀書筆記,作為本人的一份學習總結,也希望和朋友們進行交流學習。

該書是The Elements of Statistical Learning 的R語言簡明版,包含了對算法的簡明介紹以及其R實現,最讓我感興趣的是算法的R語言實現

  【轉載時請注明來源】:http://www.cnblogs.com/runner-ljt/

   Ljt   勿忘初心  無畏未來

   作為一個初學者,水平有限,歡迎交流指正。

 


        前兩小節介紹的模型選擇方法,要么是選擇全體自變量的一個合適子集,要么是使得某些自變量的回歸系數收縮為0.這兩種方法都是建立

在初始自變量集上,而本小節將要介紹的主成分分析(PCR)和偏最小二乘回歸(PLS)是將初始自變量轉化為新的變量進行回歸的方法。

        PCR是一種非監督學習方法,能夠有效的降低自變量的維數,消除多重共線性的影響。

        PLS是一種新型的多元統計數據分析方法,近十年來,它在理論、方法和應用方面都得到了迅速的發展。密西根大學的弗耐爾教授稱偏最小

二乘回歸為第二代回歸分析方法。不同於PCR,PLS為一種監督式的學習方法,其目的是既找到能夠解釋自變量同時也能夠解釋因變量的方向。

偏最小二乘回歸=多元線性回歸分析+典型相關分析+主成分分析。

         PLS有以下優點:

         (1)PLS是一種多因變量對多自變量的回歸建模方法

         (2)能夠在自變量存在嚴重多重共線性的情況下進行回歸建模

         (3)允許在樣本量少於自變量個數的情況下進行建模

         (4)最終模型包含所有自變量,易於辨別系統信息和噪聲,自變量的回歸系數便於解釋

 


  PCR  &  PLS

     pcr(formula,data,scale=F,validation = c("none", "CV", "LOO"))

      pls(formula,data,scale=F,validation = c("none", "CV", "LOO"))

      validation:驗證方法   CV: 10折交叉驗證  ; LOO :留一驗證

       輸出結果:  CV score : the root mean squared error  均方根誤差/標准誤差

                           the percentage of variance explained

      validationplot(object,val.type=c('RMSEP','MSEP','R2')) 驗證統計量繪圖函數

       object:mvr對象

       val.type=c('RMSEP','MSEP','R2') :  RMSEP:預測均方根誤差        ; MSEP:預測均方誤差

 

      

> library(ISLR)
> library(pls)
> set.seed(2)
> Hitters<-na.omit(Hitters)
> 
> pcr.fit<-pcr(Salary~.,data=Hitters,scale=T,validation='CV')
> summary(pcr.fit)
Data:     X dimension: 263 19 
    Y dimension: 263 1
Fit method: svdpc
Number of components considered: 19

VALIDATION: RMSEP
Cross-validated using 10 random segments.
       (Intercept)  1 comps  2 comps  3 comps  4 comps  5 comps  6 comps  7 comps  8 comps  9 comps  10 comps
CV             452    348.9    352.2    353.5    352.8    350.1    349.1    349.6    350.9    352.9     353.8
adjCV          452    348.7    351.8    352.9    352.1    349.3    348.0    348.5    349.8    351.6     352.3
       11 comps  12 comps  13 comps  14 comps  15 comps  16 comps  17 comps  18 comps  19 comps
CV        355.0     356.2     363.5     355.2     357.4     347.6     350.1     349.2     352.6
adjCV     353.4     354.5     361.6     352.8     355.2     345.5     347.6     346.7     349.8

TRAINING: % variance explained
        1 comps  2 comps  3 comps  4 comps  5 comps  6 comps  7 comps  8 comps  9 comps  10 comps  11 comps  12 comps
X         38.31    60.16    70.84    79.03    84.29    88.63    92.26    94.96    96.28     97.26     97.98     98.65
Salary    40.63    41.58    42.17    43.22    44.90    46.48    46.69    46.75    46.86     47.76     47.82     47.85
        13 comps  14 comps  15 comps  16 comps  17 comps  18 comps  19 comps
X          99.15     99.47     99.75     99.89     99.97     99.99    100.00
Salary     48.10     50.40     50.55     53.01     53.85     54.61     54.61
> 
> validationplot(pcr.fit,val.type='MSEP')
> 
> 
> 
> set.seed(1)
> pls.fit<-plsr(Salary~.,data=Hitters,scale=T,validation='CV')
> summary(pls.fit)
Data:     X dimension: 263 19 
    Y dimension: 263 1
Fit method: kernelpls
Number of components considered: 19

VALIDATION: RMSEP
Cross-validated using 10 random segments.
       (Intercept)  1 comps  2 comps  3 comps  4 comps  5 comps  6 comps  7 comps  8 comps  9 comps  10 comps  11 comps  12 comps
CV             452    346.7    342.3    341.9    343.3    344.2    343.6    340.9    338.4    338.9     337.2     335.5     336.8
adjCV          452    346.4    341.8    341.2    342.3    342.7    341.9    339.2    336.7    337.1     335.7     334.1     335.1
       13 comps  14 comps  15 comps  16 comps  17 comps  18 comps  19 comps
CV        336.5     335.7     336.1     336.2     336.1     335.9     337.6
adjCV     334.8     334.0     334.4     334.5     334.4     334.2     335.7

TRAINING: % variance explained
        1 comps  2 comps  3 comps  4 comps  5 comps  6 comps  7 comps  8 comps  9 comps  10 comps  11 comps  12 comps  13 comps
X         38.08    51.03    65.98    73.93    78.63    84.26    88.17    90.12    92.92     95.00     96.68     97.68     98.22
Salary    43.05    46.40    47.72    48.71    50.53    51.66    52.34    53.26    53.52     53.77     54.04     54.20     54.32
        14 comps  15 comps  16 comps  17 comps  18 comps  19 comps
X          98.55     98.98     99.24     99.71     99.99    100.00
Salary     54.47     54.54     54.59     54.61     54.61     54.61
> 
> validationplot(pls.fit,val.type='MSEP')

 

                     

      

                       

 

 

 

 

 


 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM