如果在发生不平衡二进制目标变量的情况下使用欠采样来训练模型,则预测方法会在假设平衡数据集的情况下计算概率。对于不平衡的数据,如何将这些概率转换为实际概率?转换参数/函数是在mlr软件包中还是在另一个软件包中实现的?例如:
a <- data.frame(y=factor(sample(0:1, prob = c(0.1,0.9), replace=T, size=100)))
a$x <- as.numeric(a$y)+rnorm(n=100, sd=1)
task <- makeClassifTask(data=a, target="y", positive="0")
learner <- makeLearner("classif.binomial", predict.type="prob")
learner <- makeUndersampleWrapper(learner, usw.rate = 0.1, usw.cl = "1")
model <- train(learner, task, subset = 1:50)
pred <- predict(model, task, subset = 51:100)
head(pred$data)
Run Code Online (Sandbox Code Playgroud) 如何保存使用mlr包训练的h2o模型并将其加载到新会话中以预测新数据集的目标变量?在下面的例子中,我尝试使用save和h2o.saveModel,但是它会抛出一个错误.
library(mlr)
a <- data.frame(y=factor(c(1,1,1,1,1,1,1,1,0,0,1,0)),
x1=rep(c("a","b", "c"), times=c(6,3,3)))
aTask <- makeClassifTask(data = a, target = "y", positive="1")
h2oLearner <- makeLearner("classif.h2o.deeplearning")
model <- train(h2oLearner, aTask)
# save mlr and h2o model separately:
save(file="saveh2omodel.rdata", list=c("model"))
h2o.saveModel(getLearnerModel(model), path="h2o_model")
# shutdown h2o and close R and open new session
h2o.shutdown()
library(mlr)
library(h2o)
h2o.init()
h2o.loadModel("h2o_model")
load(file="saveh2omodel.rdata")
#ERROR: Unexpected HTTP Status code: 412 Precondition Failed (url = http://localhost:54321/99/Models.bin/)
# Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = page, :
# ERROR MESSAGE:
# Illegal argument: dir of …Run Code Online (Sandbox Code Playgroud)