C8H10N4O2 - 1 year ago 40

R Question

I am trying to produce PMML from a regression model trained in

`caret`

`method='glm'`

`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)

An unaccepted answer on this related question for

`type='rf'`

So I'm unable to get pmml using either the matrix or the formula syntax (which I'm pretty sure produce identical

`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)

It

`some_glm_base <- glm(Class ~ Age + ForeignWorker + Housing.Own +`

Property.RealEstate + CreditHistory.Critical,

data=GermanCredit[train_rows, ], family="binomial")

pmml(some_glm_base) # works

For interoperablity, I would like to continue to use

`caret`

`some_glm`

`caret`

`pmml()`

`glm()`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**