Sklearn
- class gpype.backend.transform.sklearn.Sklearn[source]
Bases:
Fittable,IONodeFits one allow-listed scikit-learn estimator, offline and online.
The allow-list is fixed:
LinearDiscriminantAnalysisandLogisticRegression(both fromsklearn) as classifiers,StandardScalerandPCAas transformers. Anything else is refused at construction, naming the four. Construction checks the name and imports nothing; the estimator is built where the node is set up or fitted.A classifier fits on the
(time, channel, trial)block a batch run downstream ofEpochsdelivers, withytaken fromConstants.Keys.TRIALS– one flattened row per trial. Its output is one column: the index of the predicted class inestimator.classes_(kept in the fitted state for reference, as a plain list of strings when the labels are not numeric – never as an array, since an artifact carries no text arrays). Deployed online, it takes one 2-D frame – the trained epoch length, flattened the same way – and emits one prediction per frame.A transformer fits and applies on plain 2-D rows (samples x channels), in both batch and realtime. Its output channels, and a classifier’s, declare no unit: neither is in the input’s.
- Parameters:
estimator – An unfitted instance of one of the four allow-listed classes – the ordinary, author-time form, whose own
get_params()becomes part of the fitted state, and is also written into this node’s own configuration underparams– so an unfitted node’s hyperparameters still survive a document, not only a fitted one’s. Or the class’s bare name as a string, which is what a document supplies when this node is rebuilt: no live estimator object can cross that boundary, so a document-rebuilt node builds an instance of the named class fromparams(or a bare default where none was recorded), or the oneload_state()was given, when it is set up.**kwargs – Additional arguments for the parent
IONode.
- Raises:
ValueError – If estimator names or is an instance of a class outside the allow-list, or if one of its hyperparameters is not a plain JSON value (str, int, float, bool, None, or a list/dict of those) – no object may enter a document.
ImportError – From
setup()or a fit, not construction, if scikit-learn is not installed.
- class Configuration[source]
Bases:
ConfigurationConfiguration class for Sklearn parameters.
- __init__(estimator, **kwargs)[source]
Initialize the IONode with input and output port configurations.
- Parameters:
input_ports – List of input port configurations or None.
output_ports – List of output port configurations or None.
**kwargs – Additional arguments passed to parent classes.
- setup(data, port_context_in)[source]
Declare this node’s output shape.
A classifier’s output is one column – the predicted class’s index – regardless of how many channels it was trained on. A transformer’s output keeps its input’s width, except PCA, which narrows it to the number of components it was fitted with.
- fit(block, context)[source]
Fit the estimator, as a classifier or as a transformer.
- Parameters:
- Return type:
- Returns:
The estimator’s
get_params()under"params", plus its fitted array attributes.- Raises:
ValueError – If a classifier’s input is not 3-D, or the context carries no trials; if a transformer’s input is not 2-D.
- load_state(state)[source]
Adopt a state; the estimator is rebuilt from it on first use.
Deferred because a document’s artifacts are loaded wherever the document is read (see
_built()).