shap <- explain(rf1J35J,X=deridata1J35J[c(1:33)],nsim=10,
pred_wrapper = function(model,newdata){
predict(model, newdata = newdata, type = "prob")
})
出错,Error in { : task 1 failed - "'x'必需为数值"。
将分类变量转数值
deridata1J35J[, "种族5"] <- as.numeric(as.character(deridata1J35J[, "种族5"]))
deridata1J35J[, "慢性心衰1"] <- as.numeric(as.character(deridata1J35J[, "慢性心衰1"]))
deridata1J35J[, "CKD.egfr1.1"] <- as.numeric(as.character(deridata1J35J[, "CKD.egfr1.1"]))
deridata1J35J[, "脓毒血症1"] <- as.numeric(as.character(deridata1J35J[, "脓毒血症1"]))
deridata1J35J[, "医嘱_袢利尿剂_first1"] <- as.numeric(as.character(deridata1J35J[, "医嘱_袢利尿剂_first1"]))
deridata1J35J[, "医嘱_机械通气_first1"] <- as.numeric(as.character(deridata1J35J[, "医嘱_机械通气_first1"]))
deridata1J35J[, "医嘱_升压药_first1"] <- as.numeric(as.character(deridata1J35J[, "医嘱_升压药_first1"]))
deridata1J35J[, "医嘱_万古霉素_first1"] <- as.numeric(as.character(deridata1J35J[, "医嘱_万古霉素_first1"]))
> shap <- explain(rf1J35J,X=deridata1J35J,nsim=10,
+ pred_wrapper = function(model,newdata){
+ predict(model, newdata = newdata, type = "prob")
+ })
Error in { :
task 1 failed - "设定的变量‘种族5’, ‘慢性心衰1’, ‘CKD.egfr1.1’, ‘脓毒血症1’, ‘医嘱_袢利尿剂_first1’, ‘医嘱_机械通气_first1’, ‘医嘱_升压药_first1’, ‘医嘱_万古霉素_first1’的类别同拟合的类别不相符"
请问怎么解决呢?