pmml (version 1.5.4)

pmml.glm: Generate PMML for glm objects

Description

Generate the PMML representation for a glm object from package stats.

Usage

# S3 method for glm
pmml(model, model.name="General_Regression_Model",
      app.name="Rattle/PMML",
      description="Generalized Linear Regression Model",
      copyright=NULL, transforms=NULL, unknownValue=NULL,
      weights=NULL, ...)

Arguments

model

a glm object.

model.name

a name to be given to the model in the PMML code.

app.name

the name of the application that generated the PMML code.

description

a descriptive text for the Header element of the PMML code.

copyright

the copyright notice for the model.

transforms

data transformations represented in PMML via pmmlTransformations.

unknownValue

value to be used as the 'missingValueReplacement' attribute for all MiningFields.

weights

the weights used for building the model.

further arguments passed to or from other methods.

Details

The function exports the glm model in the PMML GeneralRegressionModel format.

Note on glm models for 2-class problems: a dataset where the target categorical variable has more than 2 classes may be turned into a 2-class problem by creating a new target variable that is TRUE for a particular class and FALSE for all other classes. While the R formula function allows such a transformation to be passed directly to it, this may cause issues when the model is converted to PMML. Therefore, it is advised to create a new 2-class separately, and then pass that variable to glm(). This is shown in an example below.

References

R project: Fitting Generalized Linear Models

Examples

Run this code
# NOT RUN {
data(iris)
mod <- glm(Sepal.Length ~ ., data=iris, family = "gaussian")
mod_pmml <- pmml(mod)
rm(mod,mod_pmml)

data(audit)
mod <- glm(Adjusted ~ Age + Employment + Education + Income, data=audit,family=binomial(logit))
mod_pmml <- pmml(mod)
rm(mod,mod_pmml)

##  creating a new 2-class target from a 3-class variable
data(iris)
dat <- iris[,1:4]
# add a new 2-class target "Species_setosa" before passing it to glm()
dat$Species_setosa <- iris$Species=="setosa"
mod <- glm(Species_setosa ~ ., data=dat, family=binomial(logit))
mod_pmml <- pmml(mod)
rm(dat,mod,mod_pmml)
# }

Run the code above in your browser using DataCamp Workspace