MatrixTransformer#
- class MatrixTransformer[source]#
Bases:
RuleTreeBaseTransformerTransformer that uses the data as feature matrix: tabular data as they are, time series and images flattened into one feature per value.
The numerical and categorical columns are inferred once, on the whole data set, and cached in the tree. It has no parameters and no fitted state: it is the transformer of the decision tree stumps.
- Variables:
See also
DecisionTreeStumpClassifier,DecisionTreeStumpRegressorExamples
>>> import numpy as np >>> from RuleTree.stumps.transformers import MatrixTransformer >>> X_ts = np.zeros((10, 2, 5)) # 10 time series with 2 signals of length 5 >>> MatrixTransformer().fit(X_ts, None, context=None, node_id=None, cache=None).transform(X_ts).shape (10, 10)
- supported_data_types = ('tabular', 'ts', 'image')#
- fit(X, y, idx=None, data_type=None, sample_weight=None, *, context, node_id, cache)[source]#
Compute the feature types of the (flattened) data on the whole data set.
- Parameters:
X (numpy.ndarray) – Data of the transformer’s type, all the instances.
y (numpy.ndarray) – Target, all the instances.
idx (numpy.ndarray, default=None) – Indices of the instances in the node. If None, all the instances.
data_type (str, default=None) – Type of X, used as key of the cached values.
sample_weight (numpy.ndarray, default=None) – Sample weights, all the instances.
context (RuleTree or None) – Tree being built, None outside a tree.
node_id (str or None) – Identifier of the node, e.g.
"Rl"(context.get_node_by_id(node_id)), None outside a tree.cache (dict or None) – Cache of the tree (namespace -> dictionary of values), None outside a tree: the component decides whether and how to use it (the ones of the library use
self._get_cache(cache)).
- Returns:
self
- Return type:
- transform(X, context=None, node_id=None, cache=None)[source]#
The data: tabular data as they are, time series and images flattened.
- Parameters:
X (numpy.ndarray) – Data of a supported type.
context (RuleTree, default=None) – The tree, None outside a tree.
node_id (str, default=None) – Identifier of the node of the stump, None outside a tree.
cache (dict, default=None) – Cache of the tree, when called by it; None otherwise.
- Returns:
X_transformed
- Return type:
numpy.ndarray of shape (n_samples, n_features)