bci_essentials.utils.reduce_to_single_channel
This module contains a custom transformer that reduces the dimensionality of the input data by removing all but the first channel to turn it into a 2D array.
1"""This module contains a custom transformer that reduces the dimensionality of the input data by removing all but the first channel to turn it into a 2D array.""" 2 3from sklearn.base import BaseEstimator, TransformerMixin 4 5 6class ReduceToSingleChannel(BaseEstimator, TransformerMixin): 7 def __init__(self): 8 pass 9 10 def fit(self, X, y=None): 11 # No fitting necessary for this transformer 12 return self 13 14 def transform(self, X): 15 if X.ndim == 3: 16 X = X[:, 0, :] 17 return X
class
ReduceToSingleChannel(sklearn.base.BaseEstimator, sklearn.base.TransformerMixin):
7class ReduceToSingleChannel(BaseEstimator, TransformerMixin): 8 def __init__(self): 9 pass 10 11 def fit(self, X, y=None): 12 # No fitting necessary for this transformer 13 return self 14 15 def transform(self, X): 16 if X.ndim == 3: 17 X = X[:, 0, :] 18 return X
Base class for all estimators in scikit-learn.
Inheriting from this class provides default implementations of:
- setting and getting parameters used by
GridSearchCVand friends; - textual and HTML representation displayed in terminals and IDEs;
- estimator serialization;
- parameters validation;
- data validation;
- feature names validation.
Read more in the :ref:User Guide <rolling_your_own_estimator>.
Notes
All estimators should specify all the parameters that can be set
at the class level in their __init__ as explicit keyword
arguments (no *args or **kwargs).
Examples
>>> import numpy as np
>>> from sklearn.base import BaseEstimator
>>> class MyEstimator(BaseEstimator):
... def __init__(self, *, param=1):
... self.param = param
... def fit(self, X, y=None):
... self.is_fitted_ = True
... return self
... def predict(self, X):
... return np.full(shape=X.shape[0], fill_value=self.param)
>>> estimator = MyEstimator(param=2)
>>> estimator.get_params()
{'param': 2}
>>> X = np.array([[1, 2], [2, 3], [3, 4]])
>>> y = np.array([1, 0, 1])
>>> estimator.fit(X, y).predict(X)
array([2, 2, 2])
>>> estimator.set_params(param=3).fit(X, y).predict(X)
array([3, 3, 3])