pmml_prcomp: Generate PMML for prcomp objects

View source: R/pmml_prcomp.R

pmml_prcompR Documentation

Generate PMML for prcomp objects

Description

Extract one principal component from a prcomp object together with the centering and scaling information and generate the PMML representation.

Usage

pmml_prcomp(model, j = 1, ...)

Arguments

model

A prcomp object.

j

Index of the eigenvector for which the PMML will be created. Per default, the PMML will be constructed based on the eigenvector of the first principal component.

...

Further arguments passed to pmml.lm() which make sense in the given context

Details

In general, each principal component represents a linear combination of the original input values. Therefore, the information of a single principal component can be expressed as a linear function and as such be represented as a linear model in PMML. pmml_prcomp() extracts one eigenvector from a prcomp object together with the centering and scaling information if they are present. At first, it leverages FunctionXform() from pmmlTransformations to add the centering and scaling information to an empty WrapData object. Even though this step is a kind of dirty hack, it is the only option to capture the centering and scaling as pre-processing steps in the PMML later. Next, a "minimal", artifical lm object is created based on the coefficients of the selected principal component. "minimal" in the way that all information is present which pmml.lm() from pmml needs to create a valid PMML. In a final step the pre-processing steps and the "minimal" lm object are passed to pmml.lm() to create the PMML.

Value

An object of class XMLNode which is of type PMML.

Examples

iris <- iris[, -5]
pc_iris <- prcomp(iris, center = FALSE, scale. = FALSE)
pmml_prcomp(pc_iris)

pc_iris <- prcomp(iris, center = TRUE, scale. = TRUE)
pmml_prcomp(pc_iris, 2)

alex23lemm/pmmlExtensionr documentation built on Sept. 21, 2023, 2:20 p.m.