Impute

DFMF Imputer

class imml.impute.DFMFImputer(**kwargs)[source]

Bases: DFMF

Impute missing data in a dataset using the DFMF method. [1] [2]

This class extends the DFMF class to provide functionality for filling in incomplete samples by addressing both block-wise and feature-wise missing data. As a subclass of DFMF, DFMFImputer inherits all input parameters and attributes from DFMF. Consequently, it uses the same fit method as DFMF for training the model.

References

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import DFMFImputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> transformer = DFMFImputer(n_components = 5)
>>> labels = transformer.fit_transform(Xs)
fit_transform(Xs, y=None, **fit_params)[source]

Fit to data, then impute them.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples_i, n_features_i)

    A list of different mods.

  • y (Ignored) -- Not used, present here for API consistency by convention.

  • fit_params (Ignored) -- Not used, present here for API consistency by convention.

Returns:

transformed_X -- The transformed data with filled missing samples.

Return type:

array-likes objects of shape (n_samples, n_components)

set_fit_request(*, Xs: bool | None | str = '$UNCHANGED$') DFMFImputer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in fit.

Returns:

self -- The updated object.

Return type:

object

set_transform_request(*, Xs: bool | None | str = '$UNCHANGED$') DFMFImputer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in transform.

Returns:

self -- The updated object.

Return type:

object

MOFA Imputer

class imml.impute.MOFAImputer(n_components: int = 10, impute: bool = True, data_options: dict = None, data_matrix: dict = None, model_options: dict = None, train_options: dict = None, stochastic_options: dict = None, covariates: dict = None, smooth_options: dict = None, random_state: int = None, verbose=False)[source]

Bases: MOFA

Impute missing data in a dataset using the MOFA method. [3] [4] [5]

This class extends the MOFA class to provide functionality for filling in incomplete samples by addressing both block-wise and feature-wise missing data. As a subclass of MOFA, MOFAImputer inherits all input parameters and attributes from MOFA. Consequently, it uses the same fit method as MOFA for training the model.

References

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import MOFAImputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> transformer = MOFAImputer(n_components = 5)
>>> labels = transformer.fit_transform(Xs)
fit_transform(Xs, y=None, **fit_params)[source]

Fit to data, then impute them.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples_i, n_features_i)

    A list of different mods.

  • y (Ignored) -- Not used, present here for API consistency by convention.

  • fit_params (Ignored) -- Not used, present here for API consistency by convention.

Returns:

transformed_X -- The transformed data with filled missing samples.

Return type:

array-likes objects of shape (n_samples, n_components)

set_fit_request(*, Xs: bool | None | str = '$UNCHANGED$') MOFAImputer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in fit.

Returns:

self -- The updated object.

Return type:

object

set_transform_request(*, Xs: bool | None | str = '$UNCHANGED$') MOFAImputer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in transform.

Returns:

self -- The updated object.

Return type:

object

JNMF Imputer

class imml.impute.JNMFImputer(filling: bool = False, **kwargs)[source]

Bases: JNMF

Impute missing data in a dataset using the JNMF method. [6] [7] [8] [9] [10] [11] [12] [13]

This class extends the JNMF class to provide functionality for filling in incomplete samples by addressing both block-wise and feature-wise missing data. As a subclass of JNMF, JNMFImputer inherits all input parameters and attributes from JNMF. Consequently, it uses the same fit method as JNMF training the model.

References

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import JNMFImputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> transformer = JNMFImputer(n_components = 5)
>>> labels = transformer.fit_transform(Xs)
transform(Xs)[source]

Impute unseen data.

Parameters:

Xs (list of array-likes objects) --

  • Xs length: n_mods

  • Xs[i] shape: (n_samples, n_features_i)

A list of different modalities.

Returns:

transformed_Xs -- The transformed data with filled missing samples.

Return type:

list of array-likes objects, shape (n_samples, n_features_i)

fit_transform(Xs, y=None, **fit_params)[source]

Fit to data, then impute them.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples_i, n_features_i)

    A list of different mods.

  • y (Ignored) -- Not used, present here for API consistency by convention.

  • fit_params (Ignored) -- Not used, present here for API consistency by convention.

Returns:

transformed_X -- The transformed data with filled missing samples.

Return type:

array-likes objects of shape (n_samples, n_components)

set_fit_request(*, Xs: bool | None | str = '$UNCHANGED$') JNMFImputer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in fit.

Returns:

self -- The updated object.

Return type:

object

set_transform_request(*, Xs: bool | None | str = '$UNCHANGED$') JNMFImputer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in transform.

Returns:

self -- The updated object.

Return type:

object

Missing Modality Indicator

class imml.impute.MissingModIndicator[source]

Bases: FunctionTransformer

Binary indicators for missing modalities. Apply FunctionTransformer (from Scikit-learn) with get_missing_mod_indicator as a function.

Note that this component typically should not be used in a vanilla Pipeline consisting of preprocessing and an estimator.

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import MissingModIndicator
>>> from imml.ampute import Amputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> Xs = Amputer(p= 0.2, random_state=42).fit_transform(Xs)
>>> indicator = MissingModIndicator()
>>> missing_mod = indicator.fit_transform()(Xs)
class imml.impute.get_missing_mod_indicator(Xs: list, y=None)[source]

Return a binary indicator for missing modalities.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples, n_features)

    A list of different modalities.

  • y (Ignored) -- Not used, present here for API consistency by convention.

Returns:

transformed_X -- Binary indicator for missing modalities.

Return type:

array-likes objects, shape (n_samples, n_mods)

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import get_missing_mod_indicator
>>> from imml.ampute import Amputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> Xs = Amputer(p= 0.2, random_state=42).fit_transform(Xs)
>>> missing_mod = get_missing_mod_indicator()(Xs)

Observed Modality Indicator

class imml.impute.ObservedModIndicator[source]

Bases: FunctionTransformer

Binary indicator for observed modalities. Apply FunctionTransformer (from Scikit-learn) with get_observed_mod_indicator as a function.

Note that this component typically should not be used in a vanilla Pipeline consisting of preprocessing and an estimator.

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import ObservedModIndicator
>>> from imml.ampute import Amputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> Xs = Amputer(p= 0.2, random_state=42).fit_transform(Xs)
>>> indicator = ObservedModIndicator()
>>> observed_mod = indicator.fit_transform()(Xs)
class imml.impute.get_observed_mod_indicator(Xs: list, y=None)[source]

Return a binary indicator for observed modalities.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples, n_features)

    A list of different modalities.

  • y (Ignored) -- Not used, present here for API consistency by convention.

Returns:

transformed_X -- Binary indicator for observed modalities.

Return type:

array-likes objects, shape (n_samples, n_mods)

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import get_observed_mod_indicator
>>> from imml.ampute import Amputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> Xs = Amputer(p= 0.2, random_state=42).fit_transform(Xs)
>>> observed_mod = get_observed_mod_indicator()(Xs)

Simple Modality Imputer

class imml.impute.SimpleModImputer(value: str = 'mean')[source]

Bases: BaseEstimator, TransformerMixin

Fill incomplete samples of a dataset using a specified method.

Parameters:

value (str, optional (default='mean')) -- The method to use for filling missing modalities. Possible values: - 'mean': replace missing samples with the mean of each feature in the corresponding modality. - 'zeros': replace missing samples with zeros.

features_mod_mean_list_

The mean value of each feature in the corresponding modality, if value='mean'

Type:

array-like of shape (n_mods,)

Example

>>> import numpy as np
>>> import pandas as pd
>>> from imml.impute import SimpleModImputer
>>> from imml.ampute import Amputer
>>> Xs = [pd.DataFrame(np.random.default_rng(42).random((20, 10))) for i in range(3)]
>>> amp = Amputer(p=0.3, random_state=42)
>>> Xs = amp.fit_transform(Xs)
>>> transformer = SimpleModImputer(value = 'mean')
>>> transformer.fit_transform(Xs)
fit(Xs: list, y=None)[source]

Fit the transformer to the input data.

Parameters:
  • Xs (list of array-likes objects) --

    • Xs length: n_mods

    • Xs[i] shape: (n_samples, n_features_i)

    A list of different modalities.

  • y (Ignored) -- Not used, present here for API consistency by convention.

Returns:

self

Return type:

returns an instance of self.

transform(Xs: list)[source]

Transform the input data by filling missing samples.

Parameters:

Xs (list of array-likes objects) --

  • Xs length: n_mods

  • Xs[i] shape: (n_samples, n_features_i)

A list of different modalities.

Returns:

transformed_Xs -- The transformed data with filled missing samples.

Return type:

list of array-likes objects, shape (n_samples, n_features_i)

set_fit_request(*, Xs: bool | None | str = '$UNCHANGED$') SimpleModImputer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in fit.

Returns:

self -- The updated object.

Return type:

object

set_transform_request(*, Xs: bool | None | str = '$UNCHANGED$') SimpleModImputer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

Xs (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) -- Metadata routing for Xs parameter in transform.

Returns:

self -- The updated object.

Return type:

object