You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warning: Unknown or uninitialised column: `values`.Error in `$<-` at parsnip/R/predict_class.R:51:9:
! Assigned data `factor(as.character(res$values), levels = object$lvl, ordered = object$ordered)` must be compatible with existing data.
✖ Existing data has 8 rows.
✖ Assigned data has 0 rows.
ℹ Only vectors of size 1 are recycled.
Caused by error in `vectbl_recycle_rhs_rows()` at tibble/R/subassign-backend.R:35:5:
! Can't recycle input of size 0 to size 8.
Run `rlang::last_trace()` to see where the error occurred.
After looking at parsnip's source code, I think I know what is going on:
if (is.data.frame(res) && ncol(res) ==1&& is.factor(res[[1]])) {
res<-res[[1]]
} else {
res$values<-factor(as.character(res$values),
levels=object$lvl,
ordered=object$ordered)
}
}
}
Although the object returned by parsnip::format_class is a data.frame with 1 column, the first column isn't a factor but characters. Therefore, the first condition fails, and control is given to the else branch, trying to access a non-existent column res$values.
The text was updated successfully, but these errors were encountered:
The problem
I registered my own parsnip model for classification.
In
set_pred
, I used apost
function to post-process my results into the expected form like this:where
prob_to_class_2
is a reimplementation of parsnip's (not exported) function:However, this gave me the following error:
After looking at parsnip's source code, I think I know what is going on:
parsnip/R/predict_class.R
Lines 37 to 56 in 04d1bc9
Although the object returned by parsnip::format_class is a data.frame with 1 column, the first column isn't a factor but characters. Therefore, the first condition fails, and control is given to the else branch, trying to access a non-existent column
res$values
.The text was updated successfully, but these errors were encountered: