ObliqueTransformer#
- class ObliqueTransformer[source]#
Bases:
RuleTreeBaseTransformer,ABCBase class of the transformers into linear combinations of the numerical features (oblique directions): each column of the feature matrix is
X[:, numerical] @ coefficients_[:, j], so a threshold on it is an oblique hyperplane, e.g.0.8 * X_2 - 0.6 * X_3 <= 1.5.The subclasses choose the directions in
fit()(_fit_directions). After the splitter has chosen a column, only its direction is kept (select).- Variables:
numerical (list of int) – Numerical columns of the feature matrix (all of them).
categorical (list of int) – Categorical columns of the feature matrix (none).
num_pre_transformed (list of int) – Numerical columns of the data, the inputs of the combinations.
coefficients (numpy.ndarray of shape (n_numerical_features, n_directions)) – Coefficients of each direction (only the chosen one after
select).
See also
- supported_data_types = ('tabular',)#
- fit(X, y, idx=None, data_type=None, sample_weight=None, *, context, node_id, cache)[source]#
Choose the oblique directions on the numerical features of the instances in the node.
- Parameters:
X (numpy.ndarray) – Tabular data, 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:
- Raises:
NoSplitFoundWarning – If the data have no numerical feature.
- transform(X, context=None, node_id=None, cache=None)[source]#
Projection of the instances on the oblique directions (on the chosen one, after select).
- Parameters:
X (numpy.ndarray) – Tabular data.
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_directions)
- combination(feature: int) tuple[list, list][source]#
Features and coefficients of a direction: the column is
sum(c * X[:, f]).- Parameters:
feature (int) – Column of the feature matrix.
- Returns:
features (list of int) – Columns of the data with a non-zero coefficient.
coefficients (list of float) – Their coefficients.
- oblique_features() list[source]#
Columns of the data combined by the oblique directions, i.e. the ones with more than one non-zero coefficient (the axis-parallel directions are ignored). Used by the oblique pivot stumps to choose the discriminative pivots.
- get_state()[source]#
Fitted state: the numerical features and the coefficients of the directions.
- Returns:
state – JSON-friendly dictionary, restored by set_state.
- Return type: