HouseholderTransformer#
- class HouseholderTransformer(max_oblique_features=2, tau=0.0001, random_state=None)[source]#
Bases:
ObliqueTransformerTransformer into the oblique directions given by a Householder reflection: the reflection that maps the principal component of the instances of the node onto the closest axis.
The reflected axes
H = I - 2 u u^Tare the columns of the feature matrix: the splitter chooses the best threshold on one of them. The reflection vectoruis restricted to themax_oblique_featuresfeatures with the largest weights, so that each oblique direction combines at most that many features (plus the axis itself); the axes not involved in the reflection stay axis-parallel. The directions are computed on the numerical features of the node, as they are: scale the data beforehand if the features have different scales.- Parameters:
max_oblique_features (int, default=2) – Maximum number of features in the reflection vector.
tau (float, default=1e-4) – If the principal component is closer than tau to every axis, the directions are the axes (no reflection).
random_state (int, RandomState instance or None, default=None) – Seed of the randomized solver of the PCA, used on large nodes.
- Variables:
numerical (list of int) – Numerical columns of the feature matrix.
categorical (list of int) – Categorical columns of the feature matrix (none).
num_pre_transformed (list of int) – Numerical columns of the data.
coefficients (numpy.ndarray of shape (n_numerical_features, n_directions)) – The columns of the reflection
H(only the chosen one afterselect).
See also
BivariateTransformeroblique directions on pairs of features.
ObliqueDecisionTreeStumpClassifier,ObliqueDecisionTreeStumpRegressorExamples
>>> from sklearn.datasets import load_iris >>> from RuleTree.stumps.transformers import HouseholderTransformer >>> X, y = load_iris(return_X_y=True) >>> transformer = HouseholderTransformer().fit(X, y, context=None, node_id=None, cache=None) >>> transformer.transform(X).shape # one column per reflected axis (150, 4) >>> features, coefficients = transformer.combination(1) # the reflected axis of feature 1 >>> features, [round(c, 3) for c in coefficients] ([1, 2], [-0.085, 0.857])