Skip to contents

This function conducts principal component analysis for features extracted from keras model.

Usage

AUTO_VI$feature_pca(
  feature = self$select_feature(self$check_result$observed),
  null_feature = self$select_feature(self$check_result$null),
  boot_feature = self$select_feature(self$check_result$boot),
  center = TRUE,
  scale = TRUE
)

Arguments

feature

Dataframe. A data frame where columns represent features and rows represent observations. It should have only one row.

null_feature

Dataframe. A data frame where columns represent features and rows represent observations. These features are extracted during the evaluation of null plots.

boot_feature

Dataframe. A data frame where columns represent features and rows represent observations. These features are extracted during the evaluation of bootstrapped plots.

center

Boolean. Whether to subtract the mean from the feature.

scale

Boolean. Whether to divide the feature by its standard deviation.

Value

A tibble of the raw features and the rotated features with attributes sdev and rotation representing the standard deviation of the principal components and the rotation matrix respectively.

Details

Features need to be extracted while running the method AUTO_VI$check() and AUTO_VI$lineup_check() by providing the argument extract_feature_from_layer. Features with zero variance will be ignored from the analysis. See also stats::prcomp().

Examples

keras_model <- try(get_keras_model("vss_phn_32"))
if (!inherits(keras_model, "try-error")) {
  myvi <- auto_vi(lm(dist ~ speed, data = cars), keras_model)

  myvi$lineup_check(extract_feature_from_layer = "global_max_pooling2d")
  myvi$feature_pca()
}
#>  Generate null data.
#>  Generate null plots.
#>  Compute auxilary inputs.
#>  Predict visual signal strength for 19 images.
#>  Predict visual signal strength for 1 image.
#> # A tibble: 20 × 277
#>      f_1   f_2   f_3   f_4    f_5      f_6    f_7    f_8   f_9     f_10    f_11
#>    <dbl> <dbl> <dbl> <dbl>  <dbl>    <dbl>  <dbl>  <dbl> <dbl>    <dbl>   <dbl>
#>  1 0.151 0     0     0     0      0.0203   0.109  0.0203 0     0.0834   0      
#>  2 0.201 0.276 0     0     0      0        0.0200 0      0.160 0        0      
#>  3 0.476 1.33  0.928 0.950 0.0433 0.253    0.283  0.209  0.896 0        0.654  
#>  4 0.656 1.69  1.42  1.35  0.208  0.446    0.532  0.506  1.06  0.00715  1.05   
#>  5 1.08  1.99  2.15  1.91  0.516  0.762    1.01   0.980  1.24  0.122    1.70   
#>  6 0.524 0.517 0     0.328 0      0        0.0451 0.177  0.255 0        0.00740
#>  7 0.602 1.56  1.21  1.19  0.0781 0.318    0.360  0.349  1.01  0        0.879  
#>  8 0.301 0.632 0     0.341 0      0        0      0.0463 0.370 0.000554 0      
#>  9 0.927 1.62  1.61  1.50  0.237  0.527    0.679  0.699  1.01  0        1.27   
#> 10 0.361 1.38  0.851 0.913 0.0758 0.249    0.288  0.213  0.905 0        0.576  
#> 11 0.781 1.68  1.58  1.45  0.299  0.549    0.690  0.660  1.06  0.0512   1.20   
#> 12 0.271 1.12  0.542 0.628 0      0.103    0.0834 0.0423 0.816 0        0.311  
#> 13 0.985 2.01  2.04  2.10  0.754  0.864    1.20   1.11   1.13  0.411    1.77   
#> 14 1.13  2.47  2.68  2.74  0.955  1.12     1.56   1.33   1.47  0.489    2.36   
#> 15 0.280 0.647 0     0.187 0      0        0      0      0.495 0        0      
#> 16 0.328 0     0     0     0.0607 0.114    0.219  0.192  0     0.141    0      
#> 17 0.466 0.833 0.275 0.584 0.0153 0.000830 0.189  0.280  0.412 0.119    0.203  
#> 18 0.926 1.77  1.80  1.61  0.269  0.585    0.723  0.718  1.14  0        1.39   
#> 19 0.697 1.40  1.16  1.17  0.144  0.354    0.453  0.476  0.863 0        0.884  
#> 20 0.942 2.27  2.27  2.34  0.829  0.968    1.33   1.15   1.31  0.491    1.94   
#> # ℹ 266 more variables: f_12 <dbl>, f_13 <dbl>, f_14 <dbl>, f_15 <dbl>,
#> #   f_16 <dbl>, f_17 <dbl>, f_18 <dbl>, f_19 <dbl>, f_20 <dbl>, f_21 <dbl>,
#> #   f_22 <dbl>, f_23 <dbl>, f_24 <dbl>, f_25 <dbl>, f_26 <dbl>, f_27 <dbl>,
#> #   f_28 <dbl>, f_29 <dbl>, f_30 <dbl>, f_31 <dbl>, f_32 <dbl>, f_33 <dbl>,
#> #   f_34 <dbl>, f_35 <dbl>, f_36 <dbl>, f_37 <dbl>, f_38 <dbl>, f_39 <dbl>,
#> #   f_40 <dbl>, f_41 <dbl>, f_42 <dbl>, f_43 <dbl>, f_44 <dbl>, f_45 <dbl>,
#> #   f_46 <dbl>, f_47 <dbl>, f_48 <dbl>, f_49 <dbl>, f_50 <dbl>, f_51 <dbl>, …