Decoders#
Some decoders following the scikit-learn
API.
- class cebra.integrations.sklearn.decoder.Decoder(*args, **kwargs)#
Bases:
ABC
,BaseEstimator
Abstract base class for implementing a decoder.
- abstract fit(X, y)#
Fit the decoder.
- Parameters:
- Return type:
- abstract predict(X)#
Predict the data
X
.
- score(X, y)#
Returns performances of the decoder instance on the provided data
X
.- Parameters:
- Return type:
- Returns:
The R2 score on
X
.
- class cebra.integrations.sklearn.decoder.KNNDecoder(n_neighbors=3, metric='cosine')#
Bases:
Decoder
Decoder implementing the k-nearest neighbors vote.
Examples
>>> from cebra import KNNDecoder >>> import numpy as np >>> X = np.random.uniform(0, 1, (100, 50)) >>> y = np.random.uniform(0, 10, (100, 2)) >>> decoder = KNNDecoder() >>> decoder.fit(X, y) KNNDecoder() >>> score = decoder.score(X, y)
- fit(X, y)#
Fit the KNN decoder.
- Parameters:
- Return type:
- Returns:
self
, to allow chaining of operations.
- predict(X)#
Predict the targets for data
X
.- Parameters:
X (
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
]) – The data matrix.- Return type:
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
]- Returns:
A matrix with the prediction for each data sample.
- class cebra.integrations.sklearn.decoder.L1LinearRegressor(alpha=1.0)#
Bases:
Decoder
A linear model trained with L1 prior as regularizer (aka the Lasso).
Note
Examples
>>> from cebra import L1LinearRegressor >>> import numpy as np >>> X = np.random.uniform(0, 1, (100, 50)) >>> y = np.random.uniform(0, 10, (100, 2)) >>> decoder = L1LinearRegressor() >>> decoder.fit(X, y) L1LinearRegressor() >>> score = decoder.score(X, y)
- fit(X, y)#
Fit the Lasso regressor.
- Parameters:
- Return type:
- Returns:
self
, to allow chaining of operations.
- predict(X)#
Predict the targets for data
X
.- Parameters:
X (
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
]) – The data matrix.- Return type:
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
]- Returns:
A matrix with the prediction for each data sample.