Teradata Package for Python Function Reference | 17.10 - Sigmoid - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference

Product
Teradata Package for Python
Release Number
17.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
teradataml.analytics.Transformations.Sigmoid.__init__ = __init__(self, columns, style='logit', out_columns=None, datatype=None, fillna=None)
DESCRIPTION:
    Sigmoid transformation allows rescaling of continuous numeric data in a more
    sophisticated way than the Rescaling transformation function. In a Sigmoid
    transformation, a numeric column is transformed using a type of sigmoid or
    s-shaped function.
 
    These non-linear transformations are more useful in data mining than a linear
    Rescaling transformation. The Sigmoid transformation is supported for numeric
    columns only.
 
    For absolute values of x greater than or equal to  36, the value of the
    sigmoid function is effectively 1 for positive arguments or 0 for negative
    arguments, within about 15 digits of significance.
 
    Note:
        Output of this function is passed to "sigmoid" argument of "Transform"
        function from Vantage Analytic Library.
 
PARAMETERS:
    columns:
        Required Argument.
        Specifies the names of the columns to scale.
        Types: str or list of str
 
    style:
        Optional Argument.
        Specifies the style of sigmoid function to use.
        Permitted Values:
            * "logit":
                The logit function produces a continuously increasing value
                between 0 and 1.
            * "modifiedlogit":
                The modified logit function is twice the logit minus 1 and
                produces a value between -1 and 1.
            * "tanh":
                The hyperbolic tangent function also produces a value between
                -1 and 1.
        Default Value: 'logit'
        Types: str
 
    out_columns:
        Optional Argument.
        Specifies the names of the output columns.
        Note:
            Number of elements in "columns" and "out_columns" must be same.
        Types: str or list of str
 
    datatype:
        Optional Argument.
        Specifies the name of the intended datatype of the output column.
        Intended data types for the output column can be specified using either the
        teradatasqlalchemy types or the permitted strings mentioned below:
         -------------------------------------------------------------------
        | If intended SQL Data Type is  | Permitted Value to be passed is   |
        |-------------------------------------------------------------------|
        | bigint                        | bigint                            |
        | byteint                       | byteint                           |
        | char(n)                       | char,n                            |
        | date                          | date                              |
        | decimal(m,n)                  | decimal,m,n                       |
        | float                         | float                             |
        | integer                       | integer                           |
        | number(*)                     | number                            |
        | number(n)                     | number,n                          |
        | number(*,n)                   | number,*,n                        |
        | number(n,n)                   | number,n,n                        |
        | smallint                      | smallint                          |
        | time(p)                       | time,p                            |
        | timestamp(p)                  | timestamp,p                       |
        | varchar(n)                    | varchar,n                         |
        --------------------------------------------------------------------
        Notes:
            1. Argument is ignored if "columns" argument is not used.
            2. char without a size is not supported.
            3. number(*) does not include the * in its datatype format.
        Examples:
            1. If intended datatype for the output column is "bigint", then
               pass string "bigint" to the argument as shown below:
               datatype="bigint"
            2. If intended datatype for the output column is "decimal(3,5)", then
               pass string "decimal,3,5" to the argument as shown below:
               datatype="decimal,3,5"
        Types: str, BIGINT, BYTEINT, CHAR, DATE, DECIMAL, FLOAT, INTEGER, NUMBER, SMALLINT, TIME,
               TIMESTAMP, VARCHAR.
 
    fillna:
        Optional Argument.
        Specifies whether the null replacement/missing value treatment should
        be performed with sigmoid transformation or not. Output of FillNa() can be
        passed to this argument.
        Note:
            If the FillNa object is created with its arguments "columns",
            "out_columns" and "datatype", then values passed in FillNa() arguments
            are ignored. Only nullstyle information is captured from the same.
        Types: FillNa
 
RETURNS:
    An instance of Sigmoid class.
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
EXAMPLE:
    # Note:
    #   To run any transformation, user needs to use Transform() function from
    #   Vantage Analytic Library.
    #   To do so import valib first and set the "val_install_location".
    >>> from teradataml import configure, DataFrame, FillNa, Sigmoid, load_example_data, valib
    >>> configure.val_install_location = "SYSLIB"
    >>>
 
    # Load example data.
    >>> load_example_data("dataframe", "sales")
    >>>
 
    # Create the required teradataml DataFrame.
    >>> sales = DataFrame("sales")
    >>> sales
                  Feb    Jan    Mar    Apr    datetime
    accounts
    Blue Inc     90.0   50.0   95.0  101.0  04/01/2017
    Orange Inc  210.0    NaN    NaN  250.0  04/01/2017
    Red Inc     200.0  150.0  140.0    NaN  04/01/2017
    Yellow Inc   90.0    NaN    NaN    NaN  04/01/2017
    Jones LLC   200.0  150.0  140.0  180.0  04/01/2017
    Alpha Co    210.0  200.0  215.0  250.0  04/01/2017
    >>>
 
    # Example 1: Scale values in columns "Jan" and "Mar" using sigmoid function "tanh".
    #            Combine the scaling with null replacement.
    >>> fn = FillNa(style="literal", value=0)
    >>> sig = Sigmoid(style="tanh", columns=["Jan", "Mar"], fillna=fn)
 
    # Execute Transform() function.
    >>> obj = valib.Transform(data=sales, sigmoid=sig, key_columns="accounts")
    >>> obj.result
         accounts  Jan  Mar
    0    Alpha Co  1.0  1.0
    1     Red Inc  1.0  1.0
    2  Orange Inc  0.0  0.0
    3   Jones LLC  1.0  1.0
    4  Yellow Inc  0.0  0.0
    5    Blue Inc  1.0  1.0
    >>>
 
 
    # Example 2: Rescaling with Sigmoid is carried out with multiple styles.
    >>> load_example_data("dataframe", "iris_test")
    >>> df = DataFrame("iris_test")
    >>> df
         sepal_length  sepal_width  petal_length  petal_width  species
    id
    5             5.0          3.6           1.4          0.2        1
    60            5.2          2.7           3.9          1.4        2
    15            5.8          4.0           1.2          0.2        1
    30            4.7          3.2           1.6          0.2        1
    40            5.1          3.4           1.5          0.2        1
    80            5.7          2.6           3.5          1.0        2
    120           6.0          2.2           5.0          1.5        3
    70            5.6          2.5           3.9          1.1        2
    20            5.1          3.8           1.5          0.3        1
    65            5.6          2.9           3.6          1.3        2
    >>>
 
    # Rescale values in columns "sepal_length", "sepal_width", "petal_length"
    # and "petal_width" with 'logit' (default) sigmoid function.
    >>> sig_1 = Sigmoid(columns=["sepal_length", "sepal_width", "petal_length",
    ...                          "petal_width"],
    ...                 out_columns=["sl", "sw", "pl", "pw"])
    >>>
 
    # Rescale values in columns "sepal_length", "sepal_width", "petal_length"
    # and "petal_width" with 'tanh' sigmoid function.
    >>> sig_2 = Sigmoid(style="tanh",
    ...                 columns=["sepal_length", "sepal_width", "petal_length",
    ...                          "petal_width"],
    ...                 out_columns=["sl_t", "sw_t", "pl_t", "pw_t"])
    >>>
 
    # Rescale values in columns "sepal_length" and "sepal_width" with 'modifiedlogit'
    # sigmoid function.
    # Combine it with null replacement using 'median' style.
    >>> fn = FillNa(style="median")
    >>> sig_3 = Sigmoid(style="modifiedlogit", columns=["sepal_length", "sepal_width"],
    ...                 out_columns=["sl_ml", "sw_ml"], fillna=fn)
    >>>
 
    # Execute Transform() function.
    >>> obj = valib.Transform(data=df, sigmoid=[sig_1, sig_2, sig_3],
    ...                       key_columns="id")
    >>> obj.result
        id        sl        sw        pl        pw      sl_t      sw_t      pl_t      pw_t     sl_ml     sw_ml
    0    5  0.993307  0.973403  0.802184  0.549834  0.999909  0.998508  0.885352  0.197375  0.986614  0.946806
    1   60  0.994514  0.937027  0.980160  0.802184  0.999939  0.991007  0.999181  0.885352  0.989027  0.874053
    2   15  0.996982  0.982014  0.768525  0.549834  0.999982  0.999329  0.833655  0.197375  0.993963  0.964028
    3   30  0.990987  0.960834  0.832018  0.549834  0.999835  0.996682  0.921669  0.197375  0.981973  0.921669
    4   40  0.993940  0.967705  0.817574  0.549834  0.999926  0.997775  0.905148  0.197375  0.987880  0.935409
    5   80  0.996665  0.930862  0.970688  0.731059  0.999978  0.989027  0.998178  0.761594  0.993330  0.861723
    6  120  0.997527  0.900250  0.993307  0.817574  0.999988  0.975743  0.999909  0.905148  0.995055  0.800499
    7   70  0.996316  0.924142  0.980160  0.750260  0.999973  0.986614  0.999181  0.800499  0.992632  0.848284
    8   20  0.993940  0.978119  0.817574  0.574443  0.999926  0.999000  0.905148  0.291313  0.987880  0.956237
    9   65  0.996316  0.947846  0.973403  0.785835  0.999973  0.993963  0.998508  0.861723  0.992632  0.895693
    >>>