Skip to content

Transformation

framework3.plugins.filters.transformation

PCAPlugin

Bases: BaseFilter

A plugin for performing Principal Component Analysis (PCA) on input data.

This plugin integrates scikit-learn's PCA implementation into the framework3 ecosystem, allowing for easy dimensionality reduction within pipelines.

Key Features
  • Utilizes scikit-learn's PCA for dimensionality reduction
  • Supports customization of the number of components to keep
  • Provides methods for fitting the PCA model and transforming data
  • Integrates seamlessly with framework3's BaseFilter interface
  • Includes a static method for generating parameter grids for hyperparameter tuning
Usage

The PCAPlugin can be used to perform dimensionality reduction on your data:

from framework3.plugins.filters.transformation.pca import PCAPlugin
from framework3.base.base_types import XYData
import numpy as np

# Create a PCAPlugin instance
pca_plugin = PCAPlugin(n_components=2)

# Create some sample data
X = XYData.mock(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
y = None  # PCA doesn't use y for fitting

# Fit the PCA model
pca_plugin.fit(X, y)

# Transform new data
new_data = XYData.mock(np.array([[2, 3, 4], [5, 6, 7]]))
transformed_data = pca_plugin.predict(new_data)
print(transformed_data.value)  # This will be a 2x2 array

Attributes:

Name Type Description
_pca PCA

The underlying scikit-learn PCA object used for dimensionality reduction.

Methods:

Name Description
fit

XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the PCA model to the given data.

predict

XYData) -> XYData: Apply dimensionality reduction to the input data.

item_grid

List[int]) -> Dict[str, Any]: Generate a parameter grid for hyperparameter tuning.

Note

This plugin uses scikit-learn's implementation of PCA, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.

Source code in framework3/plugins/filters/transformation/pca.py
@Container.bind()
class PCAPlugin(BaseFilter):
    """
    A plugin for performing Principal Component Analysis (PCA) on input data.

    This plugin integrates scikit-learn's PCA implementation into the framework3 ecosystem,
    allowing for easy dimensionality reduction within pipelines.

    Key Features:
        - Utilizes scikit-learn's PCA for dimensionality reduction
        - Supports customization of the number of components to keep
        - Provides methods for fitting the PCA model and transforming data
        - Integrates seamlessly with framework3's BaseFilter interface
        - Includes a static method for generating parameter grids for hyperparameter tuning

    Usage:
        The PCAPlugin can be used to perform dimensionality reduction on your data:

        ```python
        from framework3.plugins.filters.transformation.pca import PCAPlugin
        from framework3.base.base_types import XYData
        import numpy as np

        # Create a PCAPlugin instance
        pca_plugin = PCAPlugin(n_components=2)

        # Create some sample data
        X = XYData.mock(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
        y = None  # PCA doesn't use y for fitting

        # Fit the PCA model
        pca_plugin.fit(X, y)

        # Transform new data
        new_data = XYData.mock(np.array([[2, 3, 4], [5, 6, 7]]))
        transformed_data = pca_plugin.predict(new_data)
        print(transformed_data.value)  # This will be a 2x2 array
        ```

    Attributes:
        _pca (PCA): The underlying scikit-learn PCA object used for dimensionality reduction.

    Methods:
        fit(x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]:
            Fit the PCA model to the given data.
        predict(x: XYData) -> XYData:
            Apply dimensionality reduction to the input data.
        item_grid(n_components: List[int]) -> Dict[str, Any]:
            Generate a parameter grid for hyperparameter tuning.

    Note:
        This plugin uses scikit-learn's implementation of PCA, which may have its own
        dependencies and requirements. Ensure that scikit-learn is properly installed
        and compatible with your environment.
    """

    def __init__(self, n_components: int = 2):
        """
        Initialize a new PCAPlugin instance.

        This constructor sets up the PCAPlugin with the specified number of components
        and initializes the underlying scikit-learn PCA object.

        Args:
            n_components (int): The number of components to keep after dimensionality reduction.
                                Defaults to 2.

        Note:
            The n_components parameter is passed directly to scikit-learn's PCA.
            Refer to scikit-learn's documentation for detailed information on this parameter.
        """
        super().__init__(
            n_components=n_components
        )  # Initialize the BaseFilter and BasePlugin parent classes.
        self._pca = PCA(n_components=n_components)

    def fit(
        self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
    ) -> Optional[float]:
        """
        Fit the PCA model to the given data.

        This method trains the PCA model on the provided input features.

        Args:
            x (XYData): The input features to fit the PCA model.
            y (Optional[XYData]): Not used in PCA, but required by the BaseFilter interface.
            evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

        Returns:
            Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

        Note:
            This method uses scikit-learn's fit method internally.
            The y parameter is ignored as PCA is an unsupervised method.
        """
        self._pca.fit(x.value)
        return None

    def predict(self, x: XYData) -> XYData:
        """
        Apply dimensionality reduction to the input data.

        This method uses the trained PCA model to transform new input data,
        reducing its dimensionality.

        Args:
            x (XYData): The input features to transform.

        Returns:
            XYData: The transformed data with reduced dimensionality, wrapped in an XYData object.

        Note:
            This method uses scikit-learn's transform method internally.
            The transformed data is wrapped in an XYData object for consistency with the framework.
        """
        return XYData.mock(self._pca.transform(x.value))

    @staticmethod
    def item_grid(n_components: List[int]) -> Dict[str, Any]:
        """
        Generate a parameter grid for hyperparameter tuning.

        This static method creates a dictionary that can be used for grid search
        over different numbers of components in PCA.

        Args:
            n_components (List[int]): A list of integers representing different numbers
                                      of components to try in the grid search.

        Returns:
            Dict[str, Any]: A dictionary with the parameter name as key and the list of
                            values to try as value.

        Note:
            This method is typically used in conjunction with hyperparameter tuning
            techniques like GridSearchCV.
        """
        return {"PCAPlugin__n_components": n_components}
__init__(n_components=2)

Initialize a new PCAPlugin instance.

This constructor sets up the PCAPlugin with the specified number of components and initializes the underlying scikit-learn PCA object.

Parameters:

Name Type Description Default
n_components int

The number of components to keep after dimensionality reduction. Defaults to 2.

2
Note

The n_components parameter is passed directly to scikit-learn's PCA. Refer to scikit-learn's documentation for detailed information on this parameter.

Source code in framework3/plugins/filters/transformation/pca.py
def __init__(self, n_components: int = 2):
    """
    Initialize a new PCAPlugin instance.

    This constructor sets up the PCAPlugin with the specified number of components
    and initializes the underlying scikit-learn PCA object.

    Args:
        n_components (int): The number of components to keep after dimensionality reduction.
                            Defaults to 2.

    Note:
        The n_components parameter is passed directly to scikit-learn's PCA.
        Refer to scikit-learn's documentation for detailed information on this parameter.
    """
    super().__init__(
        n_components=n_components
    )  # Initialize the BaseFilter and BasePlugin parent classes.
    self._pca = PCA(n_components=n_components)
fit(x, y, evaluator=None)

Fit the PCA model to the given data.

This method trains the PCA model on the provided input features.

Parameters:

Name Type Description Default
x XYData

The input features to fit the PCA model.

required
y Optional[XYData]

Not used in PCA, but required by the BaseFilter interface.

required
evaluator BaseMetric | None

An optional evaluator for the model. Not used in this method.

None

Returns:

Type Description
Optional[float]

Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

Note

This method uses scikit-learn's fit method internally. The y parameter is ignored as PCA is an unsupervised method.

Source code in framework3/plugins/filters/transformation/pca.py
def fit(
    self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
) -> Optional[float]:
    """
    Fit the PCA model to the given data.

    This method trains the PCA model on the provided input features.

    Args:
        x (XYData): The input features to fit the PCA model.
        y (Optional[XYData]): Not used in PCA, but required by the BaseFilter interface.
        evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

    Returns:
        Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

    Note:
        This method uses scikit-learn's fit method internally.
        The y parameter is ignored as PCA is an unsupervised method.
    """
    self._pca.fit(x.value)
    return None
item_grid(n_components) staticmethod

Generate a parameter grid for hyperparameter tuning.

This static method creates a dictionary that can be used for grid search over different numbers of components in PCA.

Parameters:

Name Type Description Default
n_components List[int]

A list of integers representing different numbers of components to try in the grid search.

required

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: A dictionary with the parameter name as key and the list of values to try as value.

Note

This method is typically used in conjunction with hyperparameter tuning techniques like GridSearchCV.

Source code in framework3/plugins/filters/transformation/pca.py
@staticmethod
def item_grid(n_components: List[int]) -> Dict[str, Any]:
    """
    Generate a parameter grid for hyperparameter tuning.

    This static method creates a dictionary that can be used for grid search
    over different numbers of components in PCA.

    Args:
        n_components (List[int]): A list of integers representing different numbers
                                  of components to try in the grid search.

    Returns:
        Dict[str, Any]: A dictionary with the parameter name as key and the list of
                        values to try as value.

    Note:
        This method is typically used in conjunction with hyperparameter tuning
        techniques like GridSearchCV.
    """
    return {"PCAPlugin__n_components": n_components}
predict(x)

Apply dimensionality reduction to the input data.

This method uses the trained PCA model to transform new input data, reducing its dimensionality.

Parameters:

Name Type Description Default
x XYData

The input features to transform.

required

Returns:

Name Type Description
XYData XYData

The transformed data with reduced dimensionality, wrapped in an XYData object.

Note

This method uses scikit-learn's transform method internally. The transformed data is wrapped in an XYData object for consistency with the framework.

Source code in framework3/plugins/filters/transformation/pca.py
def predict(self, x: XYData) -> XYData:
    """
    Apply dimensionality reduction to the input data.

    This method uses the trained PCA model to transform new input data,
    reducing its dimensionality.

    Args:
        x (XYData): The input features to transform.

    Returns:
        XYData: The transformed data with reduced dimensionality, wrapped in an XYData object.

    Note:
        This method uses scikit-learn's transform method internally.
        The transformed data is wrapped in an XYData object for consistency with the framework.
    """
    return XYData.mock(self._pca.transform(x.value))

StandardScalerPlugin

Bases: BaseFilter

A plugin for standardizing features by removing the mean and scaling to unit variance.

This plugin integrates scikit-learn's StandardScaler into the framework3 ecosystem, allowing for easy feature standardization within pipelines.

Key Features
  • Utilizes scikit-learn's StandardScaler for feature standardization
  • Removes the mean and scales features to unit variance
  • Provides methods for fitting the scaler and transforming data
  • Integrates seamlessly with framework3's BaseFilter interface
Usage

The StandardScalerPlugin can be used to standardize features in your data:

from framework3.plugins.filters.transformation.scaler import StandardScalerPlugin
from framework3.base.base_types import XYData
import numpy as np

# Create a StandardScalerPlugin instance
scaler_plugin = StandardScalerPlugin()

# Create some sample data
X = XYData.mock(np.array([[0, 0], [0, 0], [1, 1], [1, 1]]))
y = None  # StandardScaler doesn't use y for fitting

# Fit the StandardScaler
scaler_plugin.fit(X, y)

# Transform new data
new_data = XYData.mock(np.array([[2, 2], [-1, -1]]))
scaled_data = scaler_plugin.predict(new_data)
print(scaled_data.value)
# Output will be standardized, with mean 0 and unit variance
# For example: [[ 1.41421356  1.41421356]
#               [-1.41421356 -1.41421356]]

Attributes:

Name Type Description
_scaler StandardScaler

The underlying scikit-learn StandardScaler object used for standardization.

Methods:

Name Description
fit

XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the StandardScaler to the given data.

predict

XYData) -> XYData: Perform standardization on the input data.

Note

This plugin uses scikit-learn's implementation of StandardScaler, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.

Source code in framework3/plugins/filters/transformation/scaler.py
@Container.bind()
class StandardScalerPlugin(BaseFilter):
    """
    A plugin for standardizing features by removing the mean and scaling to unit variance.

    This plugin integrates scikit-learn's StandardScaler into the framework3 ecosystem,
    allowing for easy feature standardization within pipelines.

    Key Features:
        - Utilizes scikit-learn's StandardScaler for feature standardization
        - Removes the mean and scales features to unit variance
        - Provides methods for fitting the scaler and transforming data
        - Integrates seamlessly with framework3's BaseFilter interface

    Usage:
        The StandardScalerPlugin can be used to standardize features in your data:

        ```python
        from framework3.plugins.filters.transformation.scaler import StandardScalerPlugin
        from framework3.base.base_types import XYData
        import numpy as np

        # Create a StandardScalerPlugin instance
        scaler_plugin = StandardScalerPlugin()

        # Create some sample data
        X = XYData.mock(np.array([[0, 0], [0, 0], [1, 1], [1, 1]]))
        y = None  # StandardScaler doesn't use y for fitting

        # Fit the StandardScaler
        scaler_plugin.fit(X, y)

        # Transform new data
        new_data = XYData.mock(np.array([[2, 2], [-1, -1]]))
        scaled_data = scaler_plugin.predict(new_data)
        print(scaled_data.value)
        # Output will be standardized, with mean 0 and unit variance
        # For example: [[ 1.41421356  1.41421356]
        #               [-1.41421356 -1.41421356]]
        ```

    Attributes:
        _scaler (StandardScaler): The underlying scikit-learn StandardScaler object used for standardization.

    Methods:
        fit(x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]:
            Fit the StandardScaler to the given data.
        predict(x: XYData) -> XYData:
            Perform standardization on the input data.

    Note:
        This plugin uses scikit-learn's implementation of StandardScaler, which may have its own
        dependencies and requirements. Ensure that scikit-learn is properly installed and compatible
        with your environment.
    """

    def __init__(self):
        """
        Initialize a new StandardScalerPlugin instance.

        This constructor sets up the StandardScalerPlugin and initializes the underlying
        scikit-learn StandardScaler object.

        Note:
            No parameters are required for initialization as StandardScaler uses default settings.
            For customized scaling, consider extending this class and modifying the StandardScaler initialization.
        """
        super().__init__()  # Call the BaseFilter constructor to initialize the plugin's parameters
        self._scaler = StandardScaler()

    def fit(
        self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
    ) -> Optional[float]:
        """
        Fit the StandardScaler to the given data.

        This method computes the mean and standard deviation of the input features,
        which will be used for subsequent scaling operations.

        Args:
            x (XYData): The input features to fit the StandardScaler.
            y (Optional[XYData]): Not used in StandardScaler, but required by the BaseFilter interface.
            evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

        Returns:
            Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

        Note:
            This method uses scikit-learn's fit method internally.
            The y parameter is ignored as StandardScaler is an unsupervised method.
        """
        self._scaler.fit(x.value)
        return None  # StandardScaler doesn't use y for fitting

    def predict(self, x: XYData) -> XYData:
        """
        Perform standardization on the input data.

        This method applies the standardization transformation to new input data,
        centering and scaling the features based on the computed mean and standard deviation.

        Args:
            x (XYData): The input features to standardize.

        Returns:
            XYData: The standardized version of the input data, wrapped in an XYData object.

        Note:
            This method uses scikit-learn's transform method internally.
            The transformed data is wrapped in an XYData object for consistency with the framework.
        """
        return XYData.mock(self._scaler.transform(x.value))
__init__()

Initialize a new StandardScalerPlugin instance.

This constructor sets up the StandardScalerPlugin and initializes the underlying scikit-learn StandardScaler object.

Note

No parameters are required for initialization as StandardScaler uses default settings. For customized scaling, consider extending this class and modifying the StandardScaler initialization.

Source code in framework3/plugins/filters/transformation/scaler.py
def __init__(self):
    """
    Initialize a new StandardScalerPlugin instance.

    This constructor sets up the StandardScalerPlugin and initializes the underlying
    scikit-learn StandardScaler object.

    Note:
        No parameters are required for initialization as StandardScaler uses default settings.
        For customized scaling, consider extending this class and modifying the StandardScaler initialization.
    """
    super().__init__()  # Call the BaseFilter constructor to initialize the plugin's parameters
    self._scaler = StandardScaler()
fit(x, y, evaluator=None)

Fit the StandardScaler to the given data.

This method computes the mean and standard deviation of the input features, which will be used for subsequent scaling operations.

Parameters:

Name Type Description Default
x XYData

The input features to fit the StandardScaler.

required
y Optional[XYData]

Not used in StandardScaler, but required by the BaseFilter interface.

required
evaluator BaseMetric | None

An optional evaluator for the model. Not used in this method.

None

Returns:

Type Description
Optional[float]

Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

Note

This method uses scikit-learn's fit method internally. The y parameter is ignored as StandardScaler is an unsupervised method.

Source code in framework3/plugins/filters/transformation/scaler.py
def fit(
    self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
) -> Optional[float]:
    """
    Fit the StandardScaler to the given data.

    This method computes the mean and standard deviation of the input features,
    which will be used for subsequent scaling operations.

    Args:
        x (XYData): The input features to fit the StandardScaler.
        y (Optional[XYData]): Not used in StandardScaler, but required by the BaseFilter interface.
        evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

    Returns:
        Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

    Note:
        This method uses scikit-learn's fit method internally.
        The y parameter is ignored as StandardScaler is an unsupervised method.
    """
    self._scaler.fit(x.value)
    return None  # StandardScaler doesn't use y for fitting
predict(x)

Perform standardization on the input data.

This method applies the standardization transformation to new input data, centering and scaling the features based on the computed mean and standard deviation.

Parameters:

Name Type Description Default
x XYData

The input features to standardize.

required

Returns:

Name Type Description
XYData XYData

The standardized version of the input data, wrapped in an XYData object.

Note

This method uses scikit-learn's transform method internally. The transformed data is wrapped in an XYData object for consistency with the framework.

Source code in framework3/plugins/filters/transformation/scaler.py
def predict(self, x: XYData) -> XYData:
    """
    Perform standardization on the input data.

    This method applies the standardization transformation to new input data,
    centering and scaling the features based on the computed mean and standard deviation.

    Args:
        x (XYData): The input features to standardize.

    Returns:
        XYData: The standardized version of the input data, wrapped in an XYData object.

    Note:
        This method uses scikit-learn's transform method internally.
        The transformed data is wrapped in an XYData object for consistency with the framework.
    """
    return XYData.mock(self._scaler.transform(x.value))

pca

__all__ = ['PCAPlugin'] module-attribute
PCAPlugin

Bases: BaseFilter

A plugin for performing Principal Component Analysis (PCA) on input data.

This plugin integrates scikit-learn's PCA implementation into the framework3 ecosystem, allowing for easy dimensionality reduction within pipelines.

Key Features
  • Utilizes scikit-learn's PCA for dimensionality reduction
  • Supports customization of the number of components to keep
  • Provides methods for fitting the PCA model and transforming data
  • Integrates seamlessly with framework3's BaseFilter interface
  • Includes a static method for generating parameter grids for hyperparameter tuning
Usage

The PCAPlugin can be used to perform dimensionality reduction on your data:

from framework3.plugins.filters.transformation.pca import PCAPlugin
from framework3.base.base_types import XYData
import numpy as np

# Create a PCAPlugin instance
pca_plugin = PCAPlugin(n_components=2)

# Create some sample data
X = XYData.mock(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
y = None  # PCA doesn't use y for fitting

# Fit the PCA model
pca_plugin.fit(X, y)

# Transform new data
new_data = XYData.mock(np.array([[2, 3, 4], [5, 6, 7]]))
transformed_data = pca_plugin.predict(new_data)
print(transformed_data.value)  # This will be a 2x2 array

Attributes:

Name Type Description
_pca PCA

The underlying scikit-learn PCA object used for dimensionality reduction.

Methods:

Name Description
fit

XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the PCA model to the given data.

predict

XYData) -> XYData: Apply dimensionality reduction to the input data.

item_grid

List[int]) -> Dict[str, Any]: Generate a parameter grid for hyperparameter tuning.

Note

This plugin uses scikit-learn's implementation of PCA, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.

Source code in framework3/plugins/filters/transformation/pca.py
@Container.bind()
class PCAPlugin(BaseFilter):
    """
    A plugin for performing Principal Component Analysis (PCA) on input data.

    This plugin integrates scikit-learn's PCA implementation into the framework3 ecosystem,
    allowing for easy dimensionality reduction within pipelines.

    Key Features:
        - Utilizes scikit-learn's PCA for dimensionality reduction
        - Supports customization of the number of components to keep
        - Provides methods for fitting the PCA model and transforming data
        - Integrates seamlessly with framework3's BaseFilter interface
        - Includes a static method for generating parameter grids for hyperparameter tuning

    Usage:
        The PCAPlugin can be used to perform dimensionality reduction on your data:

        ```python
        from framework3.plugins.filters.transformation.pca import PCAPlugin
        from framework3.base.base_types import XYData
        import numpy as np

        # Create a PCAPlugin instance
        pca_plugin = PCAPlugin(n_components=2)

        # Create some sample data
        X = XYData.mock(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
        y = None  # PCA doesn't use y for fitting

        # Fit the PCA model
        pca_plugin.fit(X, y)

        # Transform new data
        new_data = XYData.mock(np.array([[2, 3, 4], [5, 6, 7]]))
        transformed_data = pca_plugin.predict(new_data)
        print(transformed_data.value)  # This will be a 2x2 array
        ```

    Attributes:
        _pca (PCA): The underlying scikit-learn PCA object used for dimensionality reduction.

    Methods:
        fit(x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]:
            Fit the PCA model to the given data.
        predict(x: XYData) -> XYData:
            Apply dimensionality reduction to the input data.
        item_grid(n_components: List[int]) -> Dict[str, Any]:
            Generate a parameter grid for hyperparameter tuning.

    Note:
        This plugin uses scikit-learn's implementation of PCA, which may have its own
        dependencies and requirements. Ensure that scikit-learn is properly installed
        and compatible with your environment.
    """

    def __init__(self, n_components: int = 2):
        """
        Initialize a new PCAPlugin instance.

        This constructor sets up the PCAPlugin with the specified number of components
        and initializes the underlying scikit-learn PCA object.

        Args:
            n_components (int): The number of components to keep after dimensionality reduction.
                                Defaults to 2.

        Note:
            The n_components parameter is passed directly to scikit-learn's PCA.
            Refer to scikit-learn's documentation for detailed information on this parameter.
        """
        super().__init__(
            n_components=n_components
        )  # Initialize the BaseFilter and BasePlugin parent classes.
        self._pca = PCA(n_components=n_components)

    def fit(
        self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
    ) -> Optional[float]:
        """
        Fit the PCA model to the given data.

        This method trains the PCA model on the provided input features.

        Args:
            x (XYData): The input features to fit the PCA model.
            y (Optional[XYData]): Not used in PCA, but required by the BaseFilter interface.
            evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

        Returns:
            Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

        Note:
            This method uses scikit-learn's fit method internally.
            The y parameter is ignored as PCA is an unsupervised method.
        """
        self._pca.fit(x.value)
        return None

    def predict(self, x: XYData) -> XYData:
        """
        Apply dimensionality reduction to the input data.

        This method uses the trained PCA model to transform new input data,
        reducing its dimensionality.

        Args:
            x (XYData): The input features to transform.

        Returns:
            XYData: The transformed data with reduced dimensionality, wrapped in an XYData object.

        Note:
            This method uses scikit-learn's transform method internally.
            The transformed data is wrapped in an XYData object for consistency with the framework.
        """
        return XYData.mock(self._pca.transform(x.value))

    @staticmethod
    def item_grid(n_components: List[int]) -> Dict[str, Any]:
        """
        Generate a parameter grid for hyperparameter tuning.

        This static method creates a dictionary that can be used for grid search
        over different numbers of components in PCA.

        Args:
            n_components (List[int]): A list of integers representing different numbers
                                      of components to try in the grid search.

        Returns:
            Dict[str, Any]: A dictionary with the parameter name as key and the list of
                            values to try as value.

        Note:
            This method is typically used in conjunction with hyperparameter tuning
            techniques like GridSearchCV.
        """
        return {"PCAPlugin__n_components": n_components}
__init__(n_components=2)

Initialize a new PCAPlugin instance.

This constructor sets up the PCAPlugin with the specified number of components and initializes the underlying scikit-learn PCA object.

Parameters:

Name Type Description Default
n_components int

The number of components to keep after dimensionality reduction. Defaults to 2.

2
Note

The n_components parameter is passed directly to scikit-learn's PCA. Refer to scikit-learn's documentation for detailed information on this parameter.

Source code in framework3/plugins/filters/transformation/pca.py
def __init__(self, n_components: int = 2):
    """
    Initialize a new PCAPlugin instance.

    This constructor sets up the PCAPlugin with the specified number of components
    and initializes the underlying scikit-learn PCA object.

    Args:
        n_components (int): The number of components to keep after dimensionality reduction.
                            Defaults to 2.

    Note:
        The n_components parameter is passed directly to scikit-learn's PCA.
        Refer to scikit-learn's documentation for detailed information on this parameter.
    """
    super().__init__(
        n_components=n_components
    )  # Initialize the BaseFilter and BasePlugin parent classes.
    self._pca = PCA(n_components=n_components)
fit(x, y, evaluator=None)

Fit the PCA model to the given data.

This method trains the PCA model on the provided input features.

Parameters:

Name Type Description Default
x XYData

The input features to fit the PCA model.

required
y Optional[XYData]

Not used in PCA, but required by the BaseFilter interface.

required
evaluator BaseMetric | None

An optional evaluator for the model. Not used in this method.

None

Returns:

Type Description
Optional[float]

Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

Note

This method uses scikit-learn's fit method internally. The y parameter is ignored as PCA is an unsupervised method.

Source code in framework3/plugins/filters/transformation/pca.py
def fit(
    self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
) -> Optional[float]:
    """
    Fit the PCA model to the given data.

    This method trains the PCA model on the provided input features.

    Args:
        x (XYData): The input features to fit the PCA model.
        y (Optional[XYData]): Not used in PCA, but required by the BaseFilter interface.
        evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

    Returns:
        Optional[float]: Always returns None as PCA doesn't have a standard evaluation metric.

    Note:
        This method uses scikit-learn's fit method internally.
        The y parameter is ignored as PCA is an unsupervised method.
    """
    self._pca.fit(x.value)
    return None
item_grid(n_components) staticmethod

Generate a parameter grid for hyperparameter tuning.

This static method creates a dictionary that can be used for grid search over different numbers of components in PCA.

Parameters:

Name Type Description Default
n_components List[int]

A list of integers representing different numbers of components to try in the grid search.

required

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: A dictionary with the parameter name as key and the list of values to try as value.

Note

This method is typically used in conjunction with hyperparameter tuning techniques like GridSearchCV.

Source code in framework3/plugins/filters/transformation/pca.py
@staticmethod
def item_grid(n_components: List[int]) -> Dict[str, Any]:
    """
    Generate a parameter grid for hyperparameter tuning.

    This static method creates a dictionary that can be used for grid search
    over different numbers of components in PCA.

    Args:
        n_components (List[int]): A list of integers representing different numbers
                                  of components to try in the grid search.

    Returns:
        Dict[str, Any]: A dictionary with the parameter name as key and the list of
                        values to try as value.

    Note:
        This method is typically used in conjunction with hyperparameter tuning
        techniques like GridSearchCV.
    """
    return {"PCAPlugin__n_components": n_components}
predict(x)

Apply dimensionality reduction to the input data.

This method uses the trained PCA model to transform new input data, reducing its dimensionality.

Parameters:

Name Type Description Default
x XYData

The input features to transform.

required

Returns:

Name Type Description
XYData XYData

The transformed data with reduced dimensionality, wrapped in an XYData object.

Note

This method uses scikit-learn's transform method internally. The transformed data is wrapped in an XYData object for consistency with the framework.

Source code in framework3/plugins/filters/transformation/pca.py
def predict(self, x: XYData) -> XYData:
    """
    Apply dimensionality reduction to the input data.

    This method uses the trained PCA model to transform new input data,
    reducing its dimensionality.

    Args:
        x (XYData): The input features to transform.

    Returns:
        XYData: The transformed data with reduced dimensionality, wrapped in an XYData object.

    Note:
        This method uses scikit-learn's transform method internally.
        The transformed data is wrapped in an XYData object for consistency with the framework.
    """
    return XYData.mock(self._pca.transform(x.value))

scaler

__all__ = ['StandardScalerPlugin'] module-attribute
StandardScalerPlugin

Bases: BaseFilter

A plugin for standardizing features by removing the mean and scaling to unit variance.

This plugin integrates scikit-learn's StandardScaler into the framework3 ecosystem, allowing for easy feature standardization within pipelines.

Key Features
  • Utilizes scikit-learn's StandardScaler for feature standardization
  • Removes the mean and scales features to unit variance
  • Provides methods for fitting the scaler and transforming data
  • Integrates seamlessly with framework3's BaseFilter interface
Usage

The StandardScalerPlugin can be used to standardize features in your data:

from framework3.plugins.filters.transformation.scaler import StandardScalerPlugin
from framework3.base.base_types import XYData
import numpy as np

# Create a StandardScalerPlugin instance
scaler_plugin = StandardScalerPlugin()

# Create some sample data
X = XYData.mock(np.array([[0, 0], [0, 0], [1, 1], [1, 1]]))
y = None  # StandardScaler doesn't use y for fitting

# Fit the StandardScaler
scaler_plugin.fit(X, y)

# Transform new data
new_data = XYData.mock(np.array([[2, 2], [-1, -1]]))
scaled_data = scaler_plugin.predict(new_data)
print(scaled_data.value)
# Output will be standardized, with mean 0 and unit variance
# For example: [[ 1.41421356  1.41421356]
#               [-1.41421356 -1.41421356]]

Attributes:

Name Type Description
_scaler StandardScaler

The underlying scikit-learn StandardScaler object used for standardization.

Methods:

Name Description
fit

XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the StandardScaler to the given data.

predict

XYData) -> XYData: Perform standardization on the input data.

Note

This plugin uses scikit-learn's implementation of StandardScaler, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.

Source code in framework3/plugins/filters/transformation/scaler.py
@Container.bind()
class StandardScalerPlugin(BaseFilter):
    """
    A plugin for standardizing features by removing the mean and scaling to unit variance.

    This plugin integrates scikit-learn's StandardScaler into the framework3 ecosystem,
    allowing for easy feature standardization within pipelines.

    Key Features:
        - Utilizes scikit-learn's StandardScaler for feature standardization
        - Removes the mean and scales features to unit variance
        - Provides methods for fitting the scaler and transforming data
        - Integrates seamlessly with framework3's BaseFilter interface

    Usage:
        The StandardScalerPlugin can be used to standardize features in your data:

        ```python
        from framework3.plugins.filters.transformation.scaler import StandardScalerPlugin
        from framework3.base.base_types import XYData
        import numpy as np

        # Create a StandardScalerPlugin instance
        scaler_plugin = StandardScalerPlugin()

        # Create some sample data
        X = XYData.mock(np.array([[0, 0], [0, 0], [1, 1], [1, 1]]))
        y = None  # StandardScaler doesn't use y for fitting

        # Fit the StandardScaler
        scaler_plugin.fit(X, y)

        # Transform new data
        new_data = XYData.mock(np.array([[2, 2], [-1, -1]]))
        scaled_data = scaler_plugin.predict(new_data)
        print(scaled_data.value)
        # Output will be standardized, with mean 0 and unit variance
        # For example: [[ 1.41421356  1.41421356]
        #               [-1.41421356 -1.41421356]]
        ```

    Attributes:
        _scaler (StandardScaler): The underlying scikit-learn StandardScaler object used for standardization.

    Methods:
        fit(x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]:
            Fit the StandardScaler to the given data.
        predict(x: XYData) -> XYData:
            Perform standardization on the input data.

    Note:
        This plugin uses scikit-learn's implementation of StandardScaler, which may have its own
        dependencies and requirements. Ensure that scikit-learn is properly installed and compatible
        with your environment.
    """

    def __init__(self):
        """
        Initialize a new StandardScalerPlugin instance.

        This constructor sets up the StandardScalerPlugin and initializes the underlying
        scikit-learn StandardScaler object.

        Note:
            No parameters are required for initialization as StandardScaler uses default settings.
            For customized scaling, consider extending this class and modifying the StandardScaler initialization.
        """
        super().__init__()  # Call the BaseFilter constructor to initialize the plugin's parameters
        self._scaler = StandardScaler()

    def fit(
        self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
    ) -> Optional[float]:
        """
        Fit the StandardScaler to the given data.

        This method computes the mean and standard deviation of the input features,
        which will be used for subsequent scaling operations.

        Args:
            x (XYData): The input features to fit the StandardScaler.
            y (Optional[XYData]): Not used in StandardScaler, but required by the BaseFilter interface.
            evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

        Returns:
            Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

        Note:
            This method uses scikit-learn's fit method internally.
            The y parameter is ignored as StandardScaler is an unsupervised method.
        """
        self._scaler.fit(x.value)
        return None  # StandardScaler doesn't use y for fitting

    def predict(self, x: XYData) -> XYData:
        """
        Perform standardization on the input data.

        This method applies the standardization transformation to new input data,
        centering and scaling the features based on the computed mean and standard deviation.

        Args:
            x (XYData): The input features to standardize.

        Returns:
            XYData: The standardized version of the input data, wrapped in an XYData object.

        Note:
            This method uses scikit-learn's transform method internally.
            The transformed data is wrapped in an XYData object for consistency with the framework.
        """
        return XYData.mock(self._scaler.transform(x.value))
__init__()

Initialize a new StandardScalerPlugin instance.

This constructor sets up the StandardScalerPlugin and initializes the underlying scikit-learn StandardScaler object.

Note

No parameters are required for initialization as StandardScaler uses default settings. For customized scaling, consider extending this class and modifying the StandardScaler initialization.

Source code in framework3/plugins/filters/transformation/scaler.py
def __init__(self):
    """
    Initialize a new StandardScalerPlugin instance.

    This constructor sets up the StandardScalerPlugin and initializes the underlying
    scikit-learn StandardScaler object.

    Note:
        No parameters are required for initialization as StandardScaler uses default settings.
        For customized scaling, consider extending this class and modifying the StandardScaler initialization.
    """
    super().__init__()  # Call the BaseFilter constructor to initialize the plugin's parameters
    self._scaler = StandardScaler()
fit(x, y, evaluator=None)

Fit the StandardScaler to the given data.

This method computes the mean and standard deviation of the input features, which will be used for subsequent scaling operations.

Parameters:

Name Type Description Default
x XYData

The input features to fit the StandardScaler.

required
y Optional[XYData]

Not used in StandardScaler, but required by the BaseFilter interface.

required
evaluator BaseMetric | None

An optional evaluator for the model. Not used in this method.

None

Returns:

Type Description
Optional[float]

Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

Note

This method uses scikit-learn's fit method internally. The y parameter is ignored as StandardScaler is an unsupervised method.

Source code in framework3/plugins/filters/transformation/scaler.py
def fit(
    self, x: XYData, y: Optional[XYData], evaluator: BaseMetric | None = None
) -> Optional[float]:
    """
    Fit the StandardScaler to the given data.

    This method computes the mean and standard deviation of the input features,
    which will be used for subsequent scaling operations.

    Args:
        x (XYData): The input features to fit the StandardScaler.
        y (Optional[XYData]): Not used in StandardScaler, but required by the BaseFilter interface.
        evaluator (BaseMetric | None): An optional evaluator for the model. Not used in this method.

    Returns:
        Optional[float]: Always returns None as StandardScaler doesn't have a standard evaluation metric.

    Note:
        This method uses scikit-learn's fit method internally.
        The y parameter is ignored as StandardScaler is an unsupervised method.
    """
    self._scaler.fit(x.value)
    return None  # StandardScaler doesn't use y for fitting
predict(x)

Perform standardization on the input data.

This method applies the standardization transformation to new input data, centering and scaling the features based on the computed mean and standard deviation.

Parameters:

Name Type Description Default
x XYData

The input features to standardize.

required

Returns:

Name Type Description
XYData XYData

The standardized version of the input data, wrapped in an XYData object.

Note

This method uses scikit-learn's transform method internally. The transformed data is wrapped in an XYData object for consistency with the framework.

Source code in framework3/plugins/filters/transformation/scaler.py
def predict(self, x: XYData) -> XYData:
    """
    Perform standardization on the input data.

    This method applies the standardization transformation to new input data,
    centering and scaling the features based on the computed mean and standard deviation.

    Args:
        x (XYData): The input features to standardize.

    Returns:
        XYData: The standardized version of the input data, wrapped in an XYData object.

    Note:
        This method uses scikit-learn's transform method internally.
        The transformed data is wrapped in an XYData object for consistency with the framework.
    """
    return XYData.mock(self._scaler.transform(x.value))