Skip to content

SimpleImputer

Replace missing values with the given strategy.

Parent type: TableTransformer

Parameters:

Name Type Description Default
strategy Strategy The strategy used to impute missing values. -
selector union<List<String>, String?> The list of columns used to fit the transformer. If None, all columns are used. null
valueToReplace union<Float, String?> The value that should be replaced. null

Examples:

pipeline example {
   val table = Table({"a": [1, null], "b": [3, 4]});
   val imputer = SimpleImputer(SimpleImputer.Strategy.Mean, selector = "a").fit(table);
   val transformedTable = imputer.transform(table);
   // Table({"a": [1, 1], "b": [3, 4]})
}
pipeline example {
   val table = Table({"a": [1, null], "b": [3, 4]});
   val imputer = SimpleImputer(SimpleImputer.Strategy.Constant(0), selector = "a").fit(table);
   val transformedTable = imputer.transform(table);
   // Table({"a": [1, 0], "b": [3, 4]})
}

Stub code in SimpleImputer.sdsstub

class SimpleImputer(
    strategy: SimpleImputer.Strategy,
    selector: union<List<String>, String, Nothing?> = null,
    @PythonName("value_to_replace") valueToReplace: union<Float, String, Nothing?> = null
) sub TableTransformer {
    /**
     * Various strategies to replace missing values.
     */
    enum Strategy {
        /**
         * Replace missing values with the given constant value.
         *
         * @param value The value to replace missing values.
         */
        @PythonName("constant")
        Constant(value: Any)

        /**
         * Replace missing values with the mean of each column.
         */
        @PythonName("mean")
        Mean

        /**
         * Replace missing values with the median of each column.
         */
        @PythonName("median")
        Median

        /**
         * Replace missing values with the mode of each column.
         */
        @PythonName("mode")
        Mode
    }

    /**
     * The strategy used to replace missing values.
     */
    attr strategy: SimpleImputer.Strategy
    /**
     * The value that should be replaced.
     */
    @PythonName("value_to_replace") attr valueToReplace: Any

    /**
     * Learn a transformation for a set of columns in a table.
     *
     * This transformer is not modified.
     *
     * @param table The table used to fit the transformer.
     *
     * @result fittedTransformer The fitted transformer.
     */
    @Pure
    fun fit(
        table: Table
    ) -> fittedTransformer: SimpleImputer

    /**
     * Learn a transformation for a set of columns in a table and apply the learned transformation to the same table.
     *
     * **Note:** Neither this transformer nor the given table are modified.
     *
     * @param table The table used to fit the transformer. The transformer is then applied to this table.
     *
     * @result fittedTransformer The fitted transformer.
     * @result transformedTable The transformed table.
     */
    @Pure
    @PythonName("fit_and_transform")
    fun fitAndTransform(
        table: Table
    ) -> (fittedTransformer: SimpleImputer, transformedTable: Table)
}

isFitted

Whether the transformer is fitted.

Type: Boolean

strategy

The strategy used to replace missing values.

Type: Strategy

valueToReplace

The value that should be replaced.

Type: Any

fit

Learn a transformation for a set of columns in a table.

This transformer is not modified.

Parameters:

Name Type Description Default
table Table The table used to fit the transformer. -

Results:

Name Type Description
fittedTransformer SimpleImputer The fitted transformer.
Stub code in SimpleImputer.sdsstub

@Pure
fun fit(
    table: Table
) -> fittedTransformer: SimpleImputer

fitAndTransform

Learn a transformation for a set of columns in a table and apply the learned transformation to the same table.

Note: Neither this transformer nor the given table are modified.

Parameters:

Name Type Description Default
table Table The table used to fit the transformer. The transformer is then applied to this table. -

Results:

Name Type Description
fittedTransformer SimpleImputer The fitted transformer.
transformedTable Table The transformed table.
Stub code in SimpleImputer.sdsstub

@Pure
@PythonName("fit_and_transform")
fun fitAndTransform(
    table: Table
) -> (fittedTransformer: SimpleImputer, transformedTable: Table)

transform

Apply the learned transformation to a table.

Note: The given table is not modified.

Parameters:

Name Type Description Default
table Table The table to which the learned transformation is applied. -

Results:

Name Type Description
transformedTable Table The transformed table.
Stub code in TableTransformer.sdsstub

@Pure
fun transform(
    table: Table
) -> transformedTable: Table

Strategy

Various strategies to replace missing values.

Stub code in SimpleImputer.sdsstub

enum Strategy {
    /**
     * Replace missing values with the given constant value.
     *
     * @param value The value to replace missing values.
     */
    @PythonName("constant")
    Constant(value: Any)

    /**
     * Replace missing values with the mean of each column.
     */
    @PythonName("mean")
    Mean

    /**
     * Replace missing values with the median of each column.
     */
    @PythonName("median")
    Median

    /**
     * Replace missing values with the mode of each column.
     */
    @PythonName("mode")
    Mode
}

Constant

Replace missing values with the given constant value.

Parameters:

Name Type Description Default
value Any The value to replace missing values. -

Mean

Replace missing values with the mean of each column.

Median

Replace missing values with the median of each column.

Mode

Replace missing values with the mode of each column.