Skip to content

Commit

Permalink
xgboostImpute fix for binary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkowa committed Nov 9, 2023
1 parent 6f05df0 commit 225f064
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/xgboostImpute.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ xgboostImpute <- function(formula, data, imp_var = TRUE,
predictions <-
predict(mod, model.matrix(formPred,subset(data, !rhs_na & lhs_na)))
if(currentClass=="factor"){
data[!rhs_na & lhs_na, lhsV] <- levels(dattmp[,lhsV])[predictions+1]
if(is.null(num_class)){
data[!rhs_na & lhs_na, lhsV] <- levels(dattmp[,lhsV])[as.numeric(predictions>.5)+1]
}else{
data[!rhs_na & lhs_na, lhsV] <- levels(dattmp[,lhsV])[predictions+1]
}
}else{
data[!rhs_na & lhs_na, lhsV] <- predictions
}
Expand Down

0 comments on commit 225f064

Please sign in to comment.