utils.ftransf package
Submodules
utils.ftransf.explicit_selector module
- class utils.ftransf.explicit_selector.ExplicitSelector(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by discarding or preserving exactly those given as input.
- Variables:
fnames (list of str) – The names of the features that must be either discarded or preserved.
preserve (bool) – The flag governing whether to preserve the given features (True, default) or not (False).
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate an ExplicitSelector.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate an ExplicitSelector.
- __init__(**kwargs)
Initialize/instantiate a ExplicitSelector.
- Parameters:
kwargs – The attributes for the ExplicitSelector.
- transform(F, y=None, fnames=None, out_prefix=None, F_fnames=None)
The fundamental feature transform logic defining the explicit selector.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().Note that, to the contrary of many other feature transformers, the logic in this transform method is not adequate to be called from the corresponding transform_pcloud (as it has been overriden to efficiently deal with point clouds as input).
- Parameters:
F_fnames (list of str) – The names of the features (columns) for the input feature space matrix F.
- transform_pcloud(pcloud, out_prefix=None, fnames=None)
Apply the explicit selector to a point cloud, overwriting the parent’s logic to send the names of the features (columns) of the matrix F.
See
feature_transformer.FeatureTransformer.transform_pcloud().
utils.ftransf.feature_transformer module
- exception utils.ftransf.feature_transformer.FeatureTransformerException(message='')
Bases:
VL3DException- Author:
Alberto M. Esmoris Pena
Class for exceptions related to feature transformation components. See
VL3DException- __init__(message='')
- class utils.ftransf.feature_transformer.FeatureTransformer(**kwargs)
Bases:
object- Author:
Alberto M. Esmoris Pena
Class for feature transformation operations.
- Variables:
fnames (list or tuple) – The names of the features to be transformed (by default).
report_path (str) – The path to write the report file reporting the behavior of the transformer.
plot_path (str) – The path to write the plot file. From some feature transformers it might be the path to the directory where many plots will be stored.
selected_features (list) – Either boolean mask or list of indices corresponding to the selected features (columns of the feature matrix).
update_and_preserve (bool) – Boolean flag to control whether to discard all features but the transformed/updated ones (False, default) or to update the transformed features and preserve all the other features (True).
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a FeatureTransformer from a key-word specification.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a FeatureTransformer.
- __init__(**kwargs)
Initialize/instantiate a FeatureTransformer.
- Parameters:
kwargs – The attributes for the FeatureTransformer.
- abstractmethod transform(F, y=None, fnames=None, out_prefix=None)
The fundamental transformation logic defining the feature transformer.
- Parameters:
F (
np.ndarray) – The input matrix of features to be transformed.y (
np.ndarray) – The vector of point-wise classes.fnames (list or tuple) – The list of features to be transformed. If None, it will be taken from the internal fnames of the feature transformer. If those are None too, then an exception will raise.
out_prefix (str) – The output prefix (OPTIONAL). It might be used by a report to particularize the output path.
- Returns:
The transformed matrix of features.
- Return type:
np.ndarray
- transform_pcloud(pcloud, fnames=None, out_prefix=None)
Apply the transform method to a point cloud.
See
feature_transformer.FeatureTransformer.transform()- Parameters:
pcloud (
PointCloud) – The point cloud to be transformed.fnames (list or tuple) – The list of features to be transformed. If None, it will be taken from the internal fnames of the feature transformer. If those are None too, then an exception will raise.
out_prefix (str) – The output prefix (OPTIONAL). It might be used by a report to particularize the output path.
- Returns:
A new point cloud that is the transformed version of the input point cloud.
- Return type:
- report(report, out_prefix=None)
Handle the way a report is reported. First, it will be reported using the logging system. Then, it will be written to a file if the transformer has a not None report_path.
- Parameters:
report – The report to be reported.
out_prefix – The output prefix in case the output path must be expanded.
- Returns:
Nothing.
- build_new_las_header(pcloud)
Build the LAS header for the output point cloud.
See
PointCloudandfeature_transformer.FeatureTransformer.transform_pcloud().- Parameters:
pcloud (
PointCloud) – The input point cloud as reference to build the header for the new point cloud.- Returns:
The LAS header for the output point cloud.
- get_names_of_transformed_features(**kwargs)
Obtain the names that correspond to the transformed features.
- Returns:
The list of strings representing the names of the transformed features.
- Return type:
list
- safely_handle_fnames(fnames=None)
Handle given fnames in a safe-way, i.e., raising an exception if no valid fnames cannot be figured out from given input and the current state of the internal variables.
- Parameters:
fnames (list of str) – Given input feature names.
- Returns:
The handled feature names.
- Return type:
list of str
utils.ftransf.kbest_selector module
- class utils.ftransf.kbest_selector.KBestSelector(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by preserving only the top k features for a particular task.
- Variables:
k (int) – The number of best features to select.
scoref (callable) – The score function f(F, y) to evaluate the features F to predict the values of y.
score_name (str) – The name of the score used for the evaluations.
kb – The internal KBest selection model.
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a KBestSelector.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a KBestSelector.
- static handle_score_from_type(spec, kwargs)
Handle the score from the specified type.
- Parameters:
spec – The specification.
kwargs – The key-word arguments being built by
kbest_selector.KBestSelector.extract_ftrasnf_args()to initialize a KBestSelector.
- Returns:
True if a valid score was obtained from the given type, False otherwise.
- __init__(**kwargs)
Initialize/instantiate a KBestSelector.
- Parameters:
kwargs – The attributes for the KBestSelector.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the k-best selector.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
utils.ftransf.minmax_normalizer module
- class utils.ftransf.minmax_normalizer.MinmaxNormalizer(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by subtracting the min and dividing by the range, i.e., the difference between max and min. Min-max normalized features will be in \([0, 1]\).
Let \(x'\) be a min-max normalized version of the feature \(x \in X\) where X is the set representing the feature’s value for many points. Thus, the min-max normalized feature can be computed as:
\[x' = \dfrac{x - \min X}{\max X - \min X}\]- Variables:
minmax (list or None) – When given, it is expected to be a list of lists. Each i-th element of the first list is a pair of two elements such that the first one gives the min for the i-th feature and the second one gives the max for the i-th feature.
frenames ((list of str) or None) – When given, the normalized features will be stored in the point cloud with these names.
target_range (
np.ndarray) – The (a, b) interval such that features will be normalized to be inside (a, b). By default, it is (0, 1).clip (bool) – Whether to clip potential values from held-out data to respect the normalization interval (True) or not (False).
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a MinmaxNormalizer.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a MinmaxNormalizer.
- __init__(**kwargs)
Initialize/instantiate a MinmaxNormalizer.
- Parameters:
kwargs – The attributes for the MinmaxNormalizer.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the MinmaxNormalizer.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
- get_names_of_transformed_features(**kwargs)
See
FeatureTransformerandfeature_transformer.FeatureTransformer.get_names_of_transformed_features()
- build_new_las_header(pcloud)
See
feature_transformer.FeatureTransformer.build_new_las_header().
utils.ftransf.pca_transformer module
- class utils.ftransf.pca_transformer.PCATransformer(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by projecting them to a lower dimensionality space defined by the singular vectors of the centered matrix of features.
See
FeatureTransformer.- Variables:
out_dim (int or float) – The number of features after the projection, i.e., the dimensionality of the output. It can be given as a float inside [0, 1] that represents how many variance must be preserved (1 preserves the 100%, 0 nothing).
whiten (False) – True to multiply the singular vectors by the square root of the number of points and divide by the corresponding singular value. False otherwise.
random_seed (int) – Optional attribute to specify a fixed random seed for the random computations of the model.
frenames (list) – The names for the output features (it must match the output dimensionality. If None, they will be determined automatically as PCA_{1}, …, PCA_{out_dim}.
pca – The internal PCA model.
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a PCATransformer.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a PCATransformer.
- __init__(**kwargs)
Initialize/instantiate a PCATransformer.
- Parameters:
kwargs – The attributes for the PCATransformer.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the PCA transformer.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
- get_names_of_transformed_features(**kwargs)
See
FeatureTransformerandfeature_transformer.FeatureTransformer.get_names_of_transformed_features()
- build_new_las_header(pcloud)
See
feature_transformer.FeatureTransformer.build_new_las_header().
utils.ftransf.percentile_selector module
- class utils.ftransf.percentile_selector.PercentileSelector(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by preserving only a given percentile of the highest scores for a particular task.
- Variables:
percentile (int) – The percentage of features that must be selected given as an integer in [0, 100].
scoref (callable) – The score function f(F, y) to evaluate the features F to predict the values of y.
score_name (path) – The name of the score used for the evaluations.
sp – The internal percentile selection model.
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a PercentileSelector.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a PercentileSelector.
- __init__(**kwargs)
Initialize/instantiate a PercentileSelector.
- Parameters:
kwargs – The attributes for the PercentileSelector.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the percentile selector.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
utils.ftransf.standardizer module
- class utils.ftransf.standardizer.Standardizer(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by subtracting the mean and dividing by the standard deviation.
Let \(z\) be a standardized version of the feature \(x\) with mean \(\mu\) and standard deviation \(\sigma\). Then, \(z\) can be computed as:
\[z = \dfrac{x-\mu}{\sigma}\]- Variables:
center (bool) – Flag to control whether to center (i.e., subtract the mean).
scale (bool) – Flag to control whether to scale (i.e., divide by the standard deviation).
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a Standardizer.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a Standardizer.
- __init__(**kwargs)
Initialize/instantiate a Standardizer.
- Parameters:
kwargs – The attributes for the Standardizer.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the Standardizer.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
- get_names_of_transformed_features(**kwargs)
See
FeatureTransformerandfeature_transformer.FeatureTransformer.get_names_of_transformed_features()
utils.ftransf.variance_selector module
- class utils.ftransf.variance_selector.VarianceSelector(**kwargs)
Bases:
FeatureTransformer- Author:
Alberto M. Esmoris Pena
Class for transforming features by discarding those which variance lies below a given threshold.
- Variables:
var_th (float) – The specified variance threshold.
vt – The internal variance threshold model.
- static extract_ftransf_args(spec)
Extract the arguments to initialize/instantiate a VarianceSelector from a key-word specification.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate a VarianceSelector.
- __init__(**kwargs)
Initialize/instantiate a VarianceSelector.
- Parameters:
kwargs – The attributes for the VarianceSelector.
- transform(F, y=None, fnames=None, out_prefix=None)
The fundamental feature transform logic defining the variance selector.
See
FeatureTransformerandfeature_transformer.FeatureTransformer.transform().
Module contents
- author:
Alberto M. Esmoris Pena
The feature transformation package contains the logic to transform features.