Skip to contents

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

Usage

AUTO_VI$feature_pca(
  feature = self$check_result$observed,
  null_feature = self$check_result$null,
  boot_feature = self$check_result$boot,
  center = TRUE,
  scale = TRUE,
  pattern = "^f_.*$"
)

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.

pattern

Character. A regrex pattern to search for features in the provided DataFrame. See also grep().

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(). By default, features are assumed to follow the naming convention "f_(index)", where index is from one to the number of features.

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 1.04  1.83  1.92  1.83   0.535 0.726  0.996 0.984  1.08   0.193   1.58  
#>  3 0.204 0.414 0     0      0     0      0     0      0.421  0       0     
#>  4 1.13  2.19  2.42  2.47   0.851 1.01   1.45  1.26   1.30   0.386   2.15  
#>  5 0.883 1.52  1.58  1.45   0.408 0.702  0.954 0.800  0.967  0       1.28  
#>  6 0.464 1.58  1.11  1.14   0.161 0.333  0.380 0.316  0.989  0.00805 0.786 
#>  7 0.225 0.356 0     0.0370 0     0      0     0      0.276  0       0     
#>  8 0.225 0.662 0     0.177  0     0      0     0      0.525  0       0     
#>  9 0.383 0     0     0      0.232 0.242  0.359 0.344  0      0.331   0     
#> 10 0.216 1.04  0.135 0.575  0     0      0     0.0894 0.507  0.0372  0.0981
#> 11 1.10  3.10  3.30  4.21   1.67  1.59   2.52  1.87   1.63   1.13    3.49  
#> 12 1.03  2.40  2.42  3.01   1.26  1.15   1.80  1.52   1.19   0.940   2.41  
#> 13 0.520 1.15  0.647 0.842  0     0.110  0.131 0.170  0.725  0       0.493 
#> 14 0.215 0.119 0     0      0     0      0     0      0.0314 0       0     
#> 15 0.429 1.07  0.615 0.704  0     0.132  0.150 0.0677 0.761  0       0.423 
#> 16 0.959 2.52  2.50  2.59   0.949 1.07   1.44  1.26   1.42   0.596   2.14  
#> 17 0.704 1.83  1.63  1.62   0.499 0.643  0.839 0.797  1.05   0.277   1.28  
#> 18 0.806 1.91  1.78  1.73   0.514 0.673  0.871 0.861  1.11   0.264   1.41  
#> 19 0.582 1.30  0.943 1.01   0.172 0.278  0.433 0.457  0.738  0.0937  0.690 
#> 20 0.275 0.695 0     0.209  0     0      0     0      0.495  0       0     
#> # ℹ 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>, …