我正在尝试使用caret
和method='glm'
训练的回归模型生成PMML。示例模型:
library('caret')
data('GermanCredit')
set.seed(123)
train_rows <- createDataPartition(GermanCredit$Class, p=0.6, list=FALSE)
train_x <- GermanCredit[train_rows, c('Age','ForeignWorker','Housing.Own',
'Property.RealEstate','CreditHistory.Critical') ]
train_y <- as.integer( GermanCredit[train_rows, 'Class'] == 'Good' )
some_glm <- train( train_x, train_y, method='glm', family='binomial',
trControl = trainControl(method='none') )
summary(some_glm$finalModel)
type='rf'
对此finalModel
library('pmml')
pmml(some_glm$finalModel)
# Error in if (model$call[[1]] == "glm") { : argument is of length zero
# Same problem if I try:
some_glm2 <- train( Class ~ Age + ForeignWorker + Housing.Own +
Property.RealEstate + CreditHistory.Critical,
data=GermanCredit[train_rows, ], family="binomial",
method='glm',
trControl = trainControl(method='none') )
pmml(some_glm2$finalModel)
的未接受回答表明无法使用矩阵界面。
所以我无法使用矩阵或公式语法(我非常确定无论如何都会产生相同的some_glm_base <- glm(Class ~ Age + ForeignWorker + Housing.Own +
Property.RealEstate + CreditHistory.Critical,
data=GermanCredit[train_rows, ], family="binomial")
pmml(some_glm_base) # works
)得到pmml:
caret
在基础glm中使用公式接口:
some_glm
对于互操作性,我想继续使用caret
。有没有办法将pmml()
中生成的glm()
转换回$(".bar_item").click(function(){
if($(".bar_item").css('margin-left') === "0px")
{
$(".bar_item").animate({"margin-left": '-=190'});
}
else
{
$(".bar_item").animate({"margin-left": '+=190'});
}
});
将接受的格式?或者,如果我想要pmml功能,我是否被迫使用{{1}}构造?
答案 0 :(得分:1)
If you set model$call[[1]]
, the pmml
function will work correctly.
So in your case you would want to:
library('pmml')
some_glm$finalModel$call[[1]] <- "glm"
pmml(some_glm$finalModel)