Teradata R Package Function Reference - FPGrowth - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The FPGrowth (Frequent Pattern Growth) function uses an FP-growth algorithm to generate association rules from patterns in a data set, and then determines their interestingness.

Usage

  td_fpgrowth_mle (
      data = NULL,
      tran.item.columns = NULL,
      tran.id.columns = NULL,
      patterns.or.rules = "both",
      groupby.columns = NULL,
      pattern.distribution.key.column = NULL,
      rule.distribution.key.column = NULL,
      compress = "nocompress",
      group.size = 4,
      min.support = 0.05,
      min.confidence = 0.8,
      max.pattern.length = "10",
      antecedent.count.range = "1-INFINITE",
      consequence.count.range = "1-1",
      delimiter = ",",
      data.sequence.column = NULL
  )

Arguments

data

Required Argument.
Specifies the name of the input tibble object of class "tbl_teradata" that contains the data set.

tran.item.columns

Required Argument.
Specifies the names of the columns that contain transaction items to analyze.

tran.id.columns

Required Argument.
Specifies the names of the columns that contain identifiers for the transaction items.

patterns.or.rules

Optional Argument. Specifies whether the function outputs patterns, rules, or both. An example of a pattern is paper, computer peripherals.
Default Value: "both"
Permitted Values: both, patterns, rules

groupby.columns

Optional Argument.
Specifies the names of columns that define the partitions into which the function groups the input data and calculates output for it. At least one column must be usable as a distribution key. If you omit this argument, then the function considers all input data to be in a single partition.
Note: Do not specify the same column in both this argument and the "tran.id.columns" argument, because this causes incorrect counting in the partitions.

pattern.distribution.key.column

Optional Argument.
Specifies the name of the column to use as the distribution key for "output.pattern.table" tbl_teradata. The default value is the first column name - "pattern_<tran.item.columns>" as generated in the "output.pattern.table" tbl_teradata.
Note: only one column name can be specified.

rule.distribution.key.column

Optional Argument.
Specifies the name of the column to use as the distribution key for "output.rule.table" tbl_teradata. The default value is the first column name - "antecedent_<tran.item.columns>" as generated in the "output.rule.table" tbl_teradata.
Note: Only one column name can be specified.

compress

Optional Argument.
Specifies the compression level of the output tbl_teradata objects. Realized compression ratios depend on both this value and the data characteristics. These ratios typically range from 3x to 12x.
Default Value: "nocompress"
Permitted Values: low, medium, high, nocompress

group.size

Optional Argument.
Specifies the number of transaction items to be assigned to each worker. This value must be an integer in the range from 1 to the number of distinct transaction items, inclusive. For a machine with limited RAM, use a relatively small value.
Default Value: 4

min.support

Optional Argument.
Specifies the minimum support value of returned patterns (including the specified support value). This value must be a floating point number in the range [0, 1].
Default Value: 0.05

min.confidence

Optional Argument.
Specifies the minimum confidence value of returned patterns (including the specified confidence value). This value must be a floating point number in the range [0, 1].
Default Value: 0.8

max.pattern.length

Optional Argument.
Specifies the maximum length of returned patterns. The length of a pattern is the sum of the item numbers in the antecedent and consequence columns. This value must be an integer greater than "2" and is specified as a string. The maximum value is specified as "INFINITE". This also limits the length of returned rules.
Default Value: "10"

antecedent.count.range

Optional Argument.
Specifies the range for the number of items in the antecedent. This argument takes the format, "lower_bound-upper_bound". The function returns only patterns for which number of items in the antecedent is in the range [lower_bound, upper_bound]. The 'lower_bound' must be an integer greater than 0 and less than or equal to the 'upper_bound'.
Default Value: "1-INFINITE"

consequence.count.range

Optional Argument.
Specifies the range for the number of items in the consequence. This argument takes the format, "lower_bound-upper_bound". The function returns only patterns for which number of items in the consequence is in the range [lower_bound, upper_bound]. The 'lower_bound' must be an integer greater than 0 and less than or equal to the 'upper_bound'.
Default Value: "1-1"

delimiter

Optional Argument.
Specifies the delimiter that separates items in the output.
Default Value: ","

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_fpgrowth_mle" which is a named list containing Teradata tbl objects.
Named list members can be referenced directly with the "$" operator using following names:

  1. output.pattern.table

  2. output.rule.table

  3. output

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("fpgrowth_example", "sales_transaction")
    
    # Create remote tibble objects.
    # Sales transaction data of an office supply chain store.
    # The column "product" specifies the items that are purchased by a
    # customer in a given transaction (column "orderid")
    sales_transaction <- tbl(con, "sales_transaction")
    
    # Compute association rules based on the pattern in the "product" column
    td_fpgrowth_out <- td_fpgrowth_mle(data = sales_transaction,
                                   tran.item.columns = "product",
                                   tran.id.columns = "orderid",
                                   groupby.columns = "region",
                                   min.support = 0.01,
                                   min.confidence = 0.0,
                                   max.pattern.length = "4"
                                   )