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

Teradata® Package for R Function Reference

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

Silhouette

Description

The td_silhouette_sqle() function refers to a method of interpretation and validation of consistency within clusters of data. The function determines how well the data is clustered among clusters.

The silhouette value determines the similarity of an object to its cluster (cohesion) compared to other clusters (separation). The silhouette plot displays a measure of how close each point in one cluster is to the points in the neighbouring clusters and thus provides a way to assess parameters like the optimal number of clusters.

The silhouette scores and its definitions are as follows:

  1. Data is not appropriately clustered

  2. Datum is on the border of two natural clusters

Notes:

  • The algorithm used in this function is of the order of N*N (where N is the number of rows). Hence, expect the query to run significantly longer as the number of rows increases in the input data.

  • This function requires the UTF8 client character set for UNICODE data.

  • This function does not support Pass Through Characters (PTCs). For information about PTCs, see Teradata Vantage™ - Analytics Database International Character Set Support.

  • This function does not support KanjiSJIS or Graphic data types.

Usage

  td_silhouette_sqle (
      data = NULL,
      accumulate = NULL,
      id.column = NULL,
      cluster.id.column = NULL,
      target.columns = NULL,
      output.type = "SCORE",
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

accumulate

Optional Argument.
Specifies the name(s) of input tbl_teradata column(s) to copy to the output.
Note:
Applicable only when "output.type" is set to 'SAMPLE_SCORES'.
Types: character OR vector of Strings (character)

id.column

Required Argument.
Specifies the column which is the unique identifier of input rows.
Types: character

cluster.id.column

Required Argument.
Specifies the column containing assigned cluster IDs for input data points.
Types: character

target.columns

Required Argument.
Specifies the columns/features to be used for calculating silhouette score.
Types: character OR vector of Strings (character)

output.type

Optional Argument.
Specifies the output type or format.
Permitted Values:

  • SCORE: Outputs Average td_silhouette_sqle Score,

  • SAMPLE_SCORES: Outputs td_silhouette_sqle Score for each input sample,

  • CLUSTER_SCORES: Outputs Average td_silhouette_sqle Score for each cluster.

Default Value: "SCORE"
Types: character

...

Specifies the generic keyword arguments SQLE functions accept.
Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not.
When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not.
When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.hash.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.order.column" accepts character OR vector of Strings (character) (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_silhouette_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):result

Examples

  
    
    # Get the current context/connection.
    con <- td_get_context()$connection
    
    # Load the example data.
    loadExampleData("tdplyr_example", "mobile_data")
    
    # Create tbl_teradata object.
    mobile_data <- tbl(con, "mobile_data")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Example 1: Find the silhouette score for each input sample.
    Silhouette_result1 <- td_silhouette_sqle(
                            accumulate=c('feature'),
                            id.column="row_id",
                            cluster.id.column="userid",
                            target.columns='value1',
                            output.type="SAMPLE_SCORES",
                            data=mobile_data)
    
    # Print the result.
    print(Silhouette_result1$result)
    
    # Example 2: Find average silhouette score of all input samples.
    Silhouette_result2 <- td_silhouette_sqle(
                            id.column="row_id",
                            cluster.id.column="userid",
                            target.columns=c("value1"),
                            data=mobile_data,
                            output.type="SCORE")
    
    # Print the result.
    print(Silhouette_result2$result)
    
    # Example 3: Find average silhouette scores of input samples for each cluster.
    Silhouette_result3 <- td_silhouette_sqle(
                            id.column="row_id",
                            cluster.id.column="userid",
                            target.columns=c("value1"),
                            data=mobile_data,
                            output.type="CLUSTER_SCORES")
    
    # Print the result.
    print(Silhouette_result3$result)