get_loading_data: Obtain and format PCA component data from a recipe or...

Description Usage Arguments Value Examples

View source: R/get_loading_data.R

Description

Obtain and format PCA component data from a recipe or workflow

Usage

1
2
3
4
5
6
7
get_loading_data(x, ...)

## S3 method for class 'recipe'
get_loading_data(x, ..., id, type = "pca")

## S3 method for class 'workflow'
get_loading_data(x, ..., id = NULL, type = "pca")

Arguments

x

A prepped recipe or fitted workflow that uses a recipe. The recipe must have used at least one recipes::step_pca() (or recipes::step_pls()).

...

An optional series of conditional statements used to filter the PCA data before plotting. See Details below.

id

A single numeric or character value that is used to pick the step with the PCA results. If a single recipes::step_pca() (or recipes::step_pls()) was used, this argument is ignored. Note: if used, id must be named.

type

A character value ("pca" or "pls") for the type of step to use.

Value

A tibble that mirrors the tidy() method for those steps. The data also includes a numeric component_number and may have been changed due to any filters supplied to ....

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(recipes)
library(parsnip)
library(workflows)
library(ggplot2)

data("Chicago", package = "modeldata")

theme_set(theme_minimal())

## -----------------------------------------------------------------------------

train_pca <-
  recipe(ridership ~ ., data = Chicago %>% dplyr::select(1:21)) %>%
  step_center(all_predictors()) %>%
  step_scale(all_predictors()) %>%
  step_pca(all_predictors())

# or when used in a workflow
lm_workflow <-
  workflow() %>%
  add_model(linear_reg() %>% set_engine("lm")) %>%
  add_recipe(train_pca)

## -----------------------------------------------------------------------------

train_pca <- prep(train_pca)

get_loading_data(train_pca, component_number <= 3)

get_loading_data(train_pca, component_number <= 3, value > 0)

## -----------------------------------------------------------------------------

lm_workflow <- lm_workflow %>% fit(data = Chicago)

get_loading_data(lm_workflow, component_number <= 3)

tidymodels/learntidymodels documentation built on Dec. 14, 2021, 5:12 p.m.