| |
Methods defined here:
- __init__(self, data=None, comparison_columns=None, case_sensitive=None, accumulate=None, data_order_column=None)
- DESCRIPTION:
The StringSimilarity function calculates the similarity between two
strings, using the specified comparison method.
The similarity is a value in the range [0, 1].
Note: This function is only available when teradataml is connected
to Vantage 1.1 or later versions.
PARAMETERS:
data:
Required Argument.
Specifies the teradataml DataFrame that contains the string pairs
to be compared.
data_order_column:
Optional Argument.
Specifies Order By columns for data.
Values to this argument can be provided as a list, if multiple
columns are used for ordering.
Types: str OR list of Strings (str)
comparison_columns:
Required Argument.
Specifies pairs of input teradataml DataFrame columns that contain
strings to be compared (column1 and column2), how to compare them
(comparison_type), and (optionally) a constant and the name of the
output column for their similarity (output_column). The similarity is
a value in the range [0, 1].
For comparison_type, use one of these values:
* "jaro": Jaro distance.
* "jaro_winkler": Jaro-Winkler distance (1 for an exact match, 0 otherwise).
If you specify this comparison type, you can specify the value of
factor p with constant. 0 ≤ p ≤ 0.25.
Default: p = 0.1
* "n_gram": N-gram similarity.
If you specify this comparison type, you can specify the value of N with
constant.
Default: N = 2
* "LD": Levenshtein distance
The number of edits needed to transform one string into the other,
where edits include insertions, deletions, or substitutions of
individual characters.
* "LDWS": Levenshtein distance without substitution.
Number of edits needed to transform one string into the other using only
insertions or deletions of individual characters.
* "OSA": Optimal string alignment distance.
Number of edits needed to transform one string into the other.
Edits are insertions, deletions, substitutions, or transpositions of
characters. A substring can be edited only once.
* "DL": Damerau-Levenshtein distance.
Like OSA, except that a substring can be edited any number of times.
* "hamming": Hamming distance.
Number of positions where corresponding characters differ (that is,
minimum number of substitutions needed to transform one string into the
other) for strings of equal length, otherwise -1 for strings of unequal
length.
* "LCS": Longest common substring.
Length of longest substring common to both strings.
* "jaccard": Jaccard index-based comparison.
* "cosine": Cosine similarity.
* "soundexcode": Only for English strings. -1 if either string has a
non-English character, otherwise, 1 if their soundex codes are the same
and 0 otherwise.
You can specify a different comparison_type for every pair of columns.
The default output_column is "sim_i", where i is the sequence number of the
column pair.
Types: str OR list of strs
case_sensitive:
Optional Argument.
Specifies whether string comparison is case-sensitive.
You can specify either one value for all pairs or
one value for each pair. If you specify one value for each pair, then
the ith value applies to the ith pair.
Default value: "False".
Types: bool OR list of bools
accumulate:
Optional Argument.
Specifies the names of input teradataml DataFrame columns to be
copied to the output teradataml DataFrame.
Types: str OR list of Strings (str)
RETURNS:
Instance of StringSimilarity.
Output teradataml DataFrames can be accessed using attribute
references, such as StringSimilarityObj.<attribute_name>.
Output teradataml DataFrame attribute name is:
result
RAISES:
TeradataMlException
EXAMPLES:
# Load example data.
load_example_data("stringsimilarity", "strsimilarity_input")
# Create teradataml DataFrame objects.
strsimilarity_input = DataFrame.from_table("strsimilarity_input")
# Example -
stringsimilarity_out = StringSimilarity(data = strsimilarity_input,
comparison_columns=['jaro (src_text1, tar_text) AS jaro1_sim',
'LD (src_text1, tar_text) AS ld1_sim',
'n_gram (src_text1, tar_text, 2) AS ngram1_sim',
'jaro_winkler (src_text1, tar_text, 0.1) AS jw1_sim'],
case_sensitive = True,
accumulate = ["id","src_text1","tar_text"]
)
# Print result DataFrame.
print(stringsimilarity_out.result)
- __repr__(self)
- Returns the string representation for a StringSimilarity class instance.
- get_build_time(self)
- Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_prediction_type(self)
- Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- get_target_column(self)
- Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
- show_query(self)
- Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.
|