plaid.pipelines.sklearn_block_wrappers ====================================== .. py:module:: plaid.pipelines.sklearn_block_wrappers .. autoapi-nested-parse:: Wrapped scikit-learn transformers and regressors for PLAID Dataset compatibility. Provides adapters to use scikit-learn estimators within the PLAID feature/block system: - WrappedPlaidSklearnTransformer: wraps a TransformerMixin - WrappedPlaidSklearnRegressor: wraps a RegressorMixin Attributes ---------- .. autoapisummary:: plaid.pipelines.sklearn_block_wrappers.Self Classes ------- .. autoapisummary:: plaid.pipelines.sklearn_block_wrappers.WrappedSklearnTransformer plaid.pipelines.sklearn_block_wrappers.WrappedSklearnRegressor Functions --------- .. autoapisummary:: plaid.pipelines.sklearn_block_wrappers.get_2Darray_from_homogeneous_identifiers Module Contents --------------- .. py:data:: Self .. py:function:: get_2Darray_from_homogeneous_identifiers(dataset: plaid.Dataset, features_identifiers: list[plaid.containers.FeatureIdentifier]) -> plaid.types.Array Returns a 2D array from a Dataset and a feature id. The function calls `dataset.get_tabular_from_homogeneous_identifiers(...)`, then removes either the second or third dimension if it has size 1, so that the output is 2D. :param dataset: A Dataset object exposing `get_tabular_from_homogeneous_identifiers`. :type dataset: Dataset :param features_identifiers: a list of input feature identifiers. :type features_identifiers: list[FeatureIdentifier] :returns: A NumPy array of shape (n_samples, n_features). :raises AssertionError: If the number of features in the output does not match the identifiers. :raises ValueError: If both the second and third dimensions have size greater than 1. .. py:class:: WrappedSklearnTransformer(sklearn_block: plaid.types.SklearnBlock, in_features_identifiers: list[plaid.containers.FeatureIdentifier], out_features_identifiers: Optional[list[plaid.containers.FeatureIdentifier]] = None) Bases: :py:obj:`sklearn.base.TransformerMixin`, :py:obj:`sklearn.base.BaseEstimator` Adapter for using a scikit-learn transformer on PLAID Datasets. Transforms tabular data extracted from homogeneous feature identifiers, and returns results as a `Dataset`. Supports forward and inverse transforms. :param sklearn_block: A scikit-learn Transformer implementing fit/transform APIs. :type sklearn_block: SklearnBlock :param in_features_identifiers: List of feature identifiers to extract input data from. :type in_features_identifiers: list[FeatureIdentifier] :param out_features_identifiers: List of feature identifiers used for outputs. If None, defaults to `in_features_identifiers`. :type out_features_identifiers: list[FeatureIdentifier], optional .. py:attribute:: sklearn_block .. py:attribute:: in_features_identifiers .. py:attribute:: out_features_identifiers :value: None .. py:method:: fit(dataset: plaid.Dataset, _y=None) -> Self Fits the underlying scikit-learn transformer on selected input features. :param dataset: A `Dataset` object containing the features to transform. :param _y: Ignored. :returns: The fitted transformer. :rtype: self .. py:method:: transform(dataset: plaid.Dataset) -> plaid.Dataset Applies the fitted transformer to the selected input features. :param dataset: A `Dataset` object to transform. :returns: Transformed features wrapped as a new `Dataset`. :rtype: Dataset .. py:method:: inverse_transform(dataset: plaid.Dataset) -> plaid.Dataset Applies inverse transformation to the output features. :param dataset: A `Dataset` object with transformed output features. :returns: Dataset with inverse-transformed features. :rtype: Dataset .. py:class:: WrappedSklearnRegressor(sklearn_block: plaid.types.SklearnBlock, in_features_identifiers: list[plaid.containers.FeatureIdentifier], out_features_identifiers: list[plaid.containers.FeatureIdentifier]) Bases: :py:obj:`sklearn.base.RegressorMixin`, :py:obj:`sklearn.base.BaseEstimator` Adapter for using a scikit-learn regressor with PLAID Dataset. Fits and predicts on tabular arrays extracted from stacked features, while preserving the feature/block structure expected by PLAID. :param sklearn_block: A scikit-learn regressor with fit/predict API. :param in_features_identifiers: List of feature identifiers for inputs. :param out_features_identifiers: List of feature identifiers for outputs. .. py:attribute:: sklearn_block .. py:attribute:: in_features_identifiers .. py:attribute:: out_features_identifiers .. py:method:: fit(dataset: plaid.Dataset, _y=None) -> Self Fits the wrapped scikit-learn regressor on the stacked input/output data. :param dataset: A `Dataset` containing both input and output features. :param _y: Ignored. :returns: The fitted regressor. :rtype: self .. py:method:: predict(dataset: plaid.Dataset) -> plaid.Dataset Predicts target values using the fitted regressor. :param dataset: A `Dataset` with input features. :returns: A new `Dataset` containing predicted target features. :rtype: Dataset