Closed ghost closed 1 year ago
Here is the stackoverflow issue:
https://stackoverflow.com/questions/74338823/getting-error-while-calculating-feature-importances-r
Hi,
I've tracked down the cause of the issue. It is a side effect of how the internal predict function works in vivid. When creating the predict function, you must include the term "data" instead of the actual name of the name of the data. Below is a small example of how to recreate and solve the issue.
#Load libraries:
library(vivid)
library(xgboost)
#Load data:
set.seed(1701)
aq <- na.omit(airquality)
#Create gbm:
gbst <- xgboost(
data = as.matrix(aq[, 1:6]),
label = as.matrix(aq[, 1]),
nrounds = 100,
verbose = 0
)
#Create predict function:
pFun <- function(fit, data, ...) predict(fit, as.matrix(data[, 1:6]))
#NOTE: In the predict function above, you must use the term 'data' in the function
#argument (i.e., do not use the actual name of the data!). You must also include
#the response variable.
#Run vivid:
set.seed(1701)
viviGBst <- vivi(
fit = gbst,
data = aq,
response = "Ozone",
reorder = FALSE,
normalized = FALSE,
predictFun = pFun
)
#Output:
viviGBst
#-------------------------------------------------------------------------
#Recreating the error:
pFun <- function(fit, data, ...) predict(fit, as.matrix(aq[, 1:6])) # used 'aq' instead of 'data'
#Run vivid:
viviGBst <- vivi(
fit = gbst,
data = aq,
response = "Ozone",
predictFun = pFun
)
Hopefully that solves the problem. But let me know if you're still having any issues!
Mr. (Dr) Inglis:
THANK YOU For the very quick response! I am grateful for your help.
I will run this code soon and share results.
Take care,
Brian
Thank you for your help.
I've included the plot VIVID made with your help.
Hello Mr. (Dr.?) Inglis:
I am really looking forward to working with your package.
I am trying to run VIVID with a xgboost machine learning model. I am following your excellent directions. However, I am getting the following error when I try to run vivi
pFun <- function(fit, data, ...) predict(fit, as.matrix(dataset_oh_1[,2:19]))
Here is the backtrace:
[[<-
(*tmp*
, vn, value =<dbl>
)[[<-.tbl_df
(*tmp*
, vn, value =<dbl>
)Someone on Stackoverflow has the same issue, but I can't find it. Sorry.