Error happened : step_pls

Hi, I’m studying the ISLR tidymodels labs materials.

At 6.6 Partial Least Squares, I met an error. Please check and advise me how to solve it.

6.6 Partial Least Squares

library(tidymodels)
library(ISLR)
Hitters ← as_tibble(Hitters) %>% filter(!is.na(Salary))

install.packages(“BiocManager”)

then install mixOmics

remove.packages(“mixOmics”)

BiocManager::install(“mixOmics”, force = TRUE)

devtools::install_github(“mixOmicsTeam/mixOmics”)

library(mixOmics)
library(lattice)
library(mgcv)
pls_reciplspls_recipe ←

  • recipe(formula = Salary ~ ., data = Hitters_train) %>%
  • step_novel(all_nominal_predictors()) %>%
  • step_dummy(all_nominal_predictors()) %>%
  • step_zv(all_predictors()) %>%
  • step_normalize(all_predictors()) %>%
  • step_pls(all_predictors(), num_comp = tune(), outcome = “Salary”)
    Calling ‘tune.pls’
    error: ‘X’ must be a numeric matrix (possibly including NA’s) with finite values

Hi @kr028210,

I am not familiar with the tidymodels package and its materials, but I can see from your pasted error message that the error is occuring when the function step_pls from the tidymodels package internally calls tune.pls() from our mixOmics package. The error occurs when the function tune.spls() checks the input X matrix to make sure it is a numeric matrix. To avoid this error you need to make sure your input X matrix is a numeric matrix - NAs are allowed but no Inf, -Inf or NaNs.

Cheers,
Eva