2

What is the difference between the summary() and print() function within the context of modeling in the caret package in R? What exactly is the variance explained here for this model with 4 components 28.52% or 21.4%?

> summary(model)
Data:   X dimension: 261 130 
    Y dimension: 261 1
Fit method: oscorespls
Number of components considered: 4
TRAINING: % variance explained
          1 comps  2 comps  3 comps  4 comps
X         90.1526    92.91    94.86    96.10
.outcome   0.8772    17.17    23.99    28.52

vs

> print(model)
Partial Least Squares 

261 samples
130 predictors

No pre-processing
Resampling: Cross-Validated (5 fold, repeated 50 times) 
Summary of sample sizes: 209, 209, 209, 208, 209, 209, ... 
Resampling results across tuning parameters:

  ncomp  RMSE      Rsquared    MAE     
  1      5.408986  0.03144022  4.129525
  2      5.124799  0.14263362  3.839493
  3      4.976591  0.19114791  3.809596
  4      4.935419  0.21415260  3.799365
  5      5.054086  0.19887704  3.886382

RMSE was used to select the optimal model using the smallest value.
The final value used for the model was ncomp = 4.
1
  • 1
    Have a look at the source code. For example, if you are running flexible discriminant analysis, then you can compare caret:::print.bagFDA and caret:::summary.bagFDA to see what each are doing differently.
    – caldwellst
    Commented Apr 7, 2020 at 13:53

1 Answer 1

1

There's two components, the first is the type of model you fitted / train and because you used a partial least square regression, summary(model) returns you information about the best model chosen by caret.

library(caret)
library(pls)

model = train(mpg ~ .,data=mtcars,
trControl=trainControl(method="cv",number=5),
method="pls")

Partial Least Squares 

32 samples
10 predictors

No pre-processing
Resampling: Cross-Validated (5 fold) 
Summary of sample sizes: 25, 27, 26, 24, 26 
Resampling results across tuning parameters:

  ncomp  RMSE      Rsquared   MAE     
  1      3.086051  0.8252487  2.571524
  2      3.129871  0.8122175  2.650973
  3      3.014511  0.8582197  2.519962

RMSE was used to select the optimal model using the smallest value.
The final value used for the model was ncomp = 3.

When you do print(model), you are looking at the results from training the model and choosing the best parameter. With pls, you are choosing the number of components and this is from caret , and will likely look the same for other methods. In the above, models with 1,2,3 components are tested and the model with 3 components is chosen because it has the least RMSE. The final model stored is under model$finalModel and you can look at it:

class(model$finalModel)
[1] "mvr"

pls:::summary.mvr(model$finalModel)
Data:   X dimension: 32 10 
    Y dimension: 32 1
Fit method: oscorespls
Number of components considered: 3
TRAINING: % variance explained
          1 comps  2 comps  3 comps
X           92.73    99.98    99.99
.outcome    74.54    74.84    83.22

From the above, you can see the summary function called is from package pls and is specific for this type of model, and summary(model) below gives you the same output:

summary(model)
Data:   X dimension: 32 10 
    Y dimension: 32 1
Fit method: oscorespls
Number of components considered: 3
TRAINING: % variance explained
          1 comps  2 comps  3 comps
X           92.73    99.98    99.99
.outcome    74.54    74.84    83.22

partial least sqaure regression is something like principal component analysis, except that the decomposition (or dimension reduction) is done on tranpose(X) * Y and the components are called latent variables. So in the summary, what you see is the proportion of variance in X (all your predictors) and .outcome (your dependent variable) that are explained by the latent variables.

2
  • Thanks for the explanation. So basically summary() is providing me with the pls model WITHOUT the resampling that was called through the caret package? Commented Apr 15, 2020 at 8:59
  • 1
    Yes more or less. In your example it's e model 4 components fitted on the full training data
    – StupidWolf
    Commented Apr 15, 2020 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.