R/input_filter.R

#' Interaction terms filter when preparing for a linear regression formula
#'
#' When extracting interaction patterns from a fitted XGBoost model to fit a linear
#' regression model, not all interaction terms can be used. Transformed features that
#' come from the same original feature can not be included in the same interaction term.
#' For example, we can't have a two way interaction term 'basisFICO_8:basisFICO_2' or a
#' three way interaciton term 'basisLTV_5:normTerm:basisLTV_3'.
#'
#' @param termName Character string indicating name of the interaction term.
#' @param matchName Character string representing a pattern for matching, e.g., 'FICO'.
#'
#' @return An integer representing number of times 'matchName' appears in 'termName'
#'
#' @export
#'
#' @examples
#' input_filter(termName = 'basisFICO_8:basisFICO_2', matchName = 'FICO')
input_filter <- function( termName, matchName ) {
  matchCount <- length( grep( matchName,
                              unlist(strsplit(termName, ":")) ) )
  return(matchCount)
}
hongqi0314/PRAuto.PMML documentation built on May 6, 2019, 11:30 a.m.