R/normDis_pmml.R

#' Function to generate PMML element that using 'NormDiscrete'
#'
#' @param featureName String of characters indicating the variable that is to be 
#'                    normalized.
#' @param featureLevel Vector of float numbers representing levels of a categorical
#'                     variable.
#' @param newFieldName String of characters indicating origin of transformed features.
#' @param purpose String of characters indicating purpose of the transformation.
#' 
#' @return PMML element 'DerivedField' with transformation 'NormDiscrete'
#' @export
#' 
#' @example 
normDis_pmml <- function(featureName, featureLevel = c(0, 1), newFieldName = featureName, purpose = 'miss') {
  LocalTransformations <- newXMLNode("LocalTransformations")
  if (purpose == 'miss') {
    DerivedField <- newXMLNode( "DerivedField", attrs = c( name = paste(purpose, newFieldName, sep = ""),
                                                           dataType = "double", optype = "continuous" ),
                                parent = LocalTransformations )
    newXMLNode( "NormDiscrete", attrs = c( field = featureName, value = featureLevel[1] ),
                parent = DerivedField )
  } else {
    for ( i in seq_along(featureLevel) ) {
      DerivedField <- newXMLNode( "DerivedField", attrs = c( name = paste(purpose, newFieldName, "_", i, sep = ""),
                                                             dataType = "double", optype = "continuous" ),
                                  parent = LocalTransformations )
      newXMLNode( "NormDiscrete", attrs = c( field = featureName, value = featureLevel[i] ),
                  parent = DerivedField )
    }
  }
  
  return(LocalTransformations)
}
hongqi0314/PRAuto.PMML documentation built on May 6, 2019, 11:30 a.m.