Skip to main content

SimpleImputer

Converter
DashAI.back.converters.scikit_learn.SimpleImputer

Fill missing values using a simple univariate per-column strategy.

Each feature is imputed independently using one of four strategies:

  • "mean": replace missing values with the column mean (numeric only).
  • "median": replace with the column median (numeric only).
  • "most_frequent": replace with the most common value (works with strings and numeric data).
  • "constant": replace with a fixed fill_value supplied by the user.

Columns with all-missing values are handled according to the keep_empty_features flag. When add_indicator=True, a MissingIndicator binary matrix is stacked onto the output.

Output typing preserves the original column type whenever the strategy does not perform arithmetic: "most_frequent" and "constant" only copy existing values, so the source type (Integer, Float, or Categorical) is kept. "mean"/"median" always produce Float64, even when the statistic happens to be a whole number, so the output type follows from the params alone and never from the data.

Wraps sklearn.impute.SimpleImputer.

References​

Parameters​

strategy : string, default=mean
The imputation strategy.
fill_value, default=None
The value to replace missing values with.
add_indicator : boolean, default=False
If True, a MissingIndicator transform will stack onto output.
keep_empty_features : boolean, default=False
If True, empty features will be kept.

Methods​

fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'SimpleImputer'

Defined on SimpleImputer

Fit the imputer, remembering the input column types.

Parameters

x : DashAIDataset
The input dataset to fit the imputer on.
y : DashAIDataset, optional
Ignored; present for API consistency.

Returns

SimpleImputer
The fitted imputer instance (self).

get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType

Defined on SimpleImputer

Return the DashAI data type produced by this converter for a column.

Parameters

column_name : str, optional
The name of the output column. Defaults to None.

Returns

DashAIDataType
Integer for the binary MissingIndicator columns appended when add_indicator=True. Otherwise, the original column type for "most_frequent"/"constant" (no arithmetic is performed on the values), and a Float type backed by pyarrow.float64() for "mean"/"median". The type never depends on the fitted statistics, so it can be known before fitting (see infer_output_columns).

infer_output_columns(self, inputs: List[Annotated[Union[DashAI.back.preprocessing.structure_types.ColumnItem, DashAI.back.preprocessing.structure_types.BlockItem], FieldInfo(annotation=NoneType, required=True, discriminator='kind')]]) -> DashAI.back.preprocessing.structure_types.StructureDelta

Defined on SimpleImputer

Estimate the output: the scope imputed in place, plus indicators.

Parameters

inputs : list of ColumnItem | BlockItem
The dataset state items in this converter's scope.

Returns

StructureDelta
The imputed inputs, plus an indicator block if requested.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_metadata(cls) -> 'Dict[str, Any]'

Defined on BaseConverter

Get metadata for the converter, used by the DashAI frontend.

Parameters

cls : type
The converter class (injected automatically by Python for classmethods).

Returns

Dict[str, Any]
Dictionary containing display name, short description, image preview path, category, icon, color, and whether the converter is supervised.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

rows_to_keep(self, x: "'DashAIDataset'") -> 'List[int]'

Defined on BaseConverter

Positions of the rows of x that survive this converter.

Parameters

x : DashAIDataset
The converter's scope columns of one split.

Returns

list of int
0-based positions of the kept rows, in order.

transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'

Defined on SklearnWrapper

Transform the data using the fitted scikit-learn transformer.

Parameters

x : DashAIDataset
The input dataset to transform.
y : DashAIDataset, optional
Not used. Present for API consistency. Defaults to None.

Returns

DashAIDataset
The transformed dataset with updated DashAI column types.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.