morphoclass.transforms.scalers package¶
Submodules¶
Module contents¶
Various feature scalers for morphology node features.
-
class
morphoclass.transforms.scalers.AbstractFeatureScaler(feature_indices, is_global_feature=False)¶ Bases:
abc.ABCBase abstract class for all feature scalers.
All derived classes must implement the _fit and _transform methods
- Parameters
feature_indices – List of indices of the feature maps to which to apply the scaling.
is_global_feature – Apply scaler to global features rather than node features.
-
fit(dataset, idx=None)¶ Fit the scaler to data.
- Parameters
dataset (morphoclass.data.MorphologyDataset) – Data to which to fit the scaler.
idx – Selects a subset of samples in the dataset to which to fit the data.
-
abstract
get_config()¶ Generate the configuration necessary for reconstructing the scaler.
- Returns
config – The configuration of the scaler. It should contain all information necessary for reconstructing the scaler using the scaler_from_config function.
- Return type
dict
-
abstract
reconstruct(params)¶ Reconstruct the configuration from parameters.
- Parameters
params (dict) – The parameters found in config[“params”] with the config being the dictionary returned by get_config.
-
class
morphoclass.transforms.scalers.FeatureManualScaler(feature_indices, shift=0, scale=1, **kwargs)¶ Bases:
morphoclass.transforms.scalers.abstract_scaler.AbstractFeatureScalerScaler that shifts and scales the features by fixed values.
The new features are computed by features -> (features - shift) / scale
- Parameters
feature_indices – List of indices of the feature maps to which to apply the scaling.
shift (float) – The fixed offset subtracted from the features
scale (float) – The fixed scale by which the shifted features are divided.
kwargs – Additional keyword argument to pass through to the AbstractFeatureScaler base class.
-
get_config()¶ Generate the configuration necessary for reconstructing the scaler.
- Returns
config – The configuration of the scaler. It should contain all information necessary for reconstructing the scaler using the scaler_from_config function.
- Return type
dict
-
reconstruct(params)¶ Reconstruct the configuration from parameters.
- Parameters
params (dict) – The parameters found in config[“params”] with the config being the dictionary returned by get_config.
-
class
morphoclass.transforms.scalers.FeatureMinMaxScaler(feature_indices, feature_range=(0, 1), take_abs=False, **kwargs)¶ Bases:
morphoclass.transforms.scalers.abstract_scaler.AbstractFeatureScalerScaler that scales the features to a given range.
Internally the MinMaxScaler from scikit-learn is applied
- Parameters
feature_indices – List of indices of the feature maps to which to apply the scaling.
feature_range (sequence (optional)) – The feature range to which to scale the features. This value is passed through to the MinMaxScaler class in sklearn.
take_abs (bool (optional)) – If true then the scaler will be fitted on the absolute values of the features. This way a feature range of (0, 1) would translate to an effective range of (-1, 1). This is useful when it’s necessary to avoid shifting the features away from the origin.
kwargs – Additional keyword argument to pass through to the AbstractFeatureScaler base class.
-
get_config()¶ Generate the configuration necessary for reconstructing the scaler.
- Returns
config – The configuration of the scaler. It should contain all information necessary for reconstructing the scaler using the scaler_from_config function.
- Return type
dict
-
reconstruct(params)¶ Reconstruct the configuration from parameters.
- Parameters
params (dict) – The parameters found in config[“params”] with the config being the dictionary returned by get_config.
-
class
morphoclass.transforms.scalers.FeatureRobustScaler(feature_indices, with_centering=True, with_scaling=True, **kwargs)¶ Bases:
morphoclass.transforms.scalers.abstract_scaler.AbstractFeatureScalerScaler that is robust against outliers in data.
Internally the RobustScaler from scikit-learn is applied.
- Parameters
feature_indices – List of indices of the feature maps to which to apply the scaling.
with_centering (bool (optional)) – If True, center the data before scaling. This value is passed through to the RobustScaler class in sklearn.
with_scaling (bool (optional)) – If True, scale the data to interquartile range. This value is passed through to the RobustScaler class in sklearn.
kwargs – Additional keyword argument to pass through to the AbstractFeatureScaler base class.
-
get_config()¶ Generate the configuration necessary for reconstructing the scaler.
- Returns
config – The configuration of the scaler. It should contain all information necessary for reconstructing the scaler using the scaler_from_config function.
- Return type
dict
-
reconstruct(params)¶ Reconstruct the configuration from parameters.
- Parameters
params (dict) – The parameters found in config[“params”] with the config being the dictionary returned by get_config.
-
class
morphoclass.transforms.scalers.FeatureStandardScaler(feature_indices, with_mean=True, with_std=True, **kwargs)¶ Bases:
morphoclass.transforms.scalers.abstract_scaler.AbstractFeatureScalerScaler that removes the mean and standard deviation.
Internally the StandardScaler from scikit-learn is applied
- Parameters
feature_indices – List of indices of the feature maps to which to apply the scaling.
with_mean (bool (optional)) – Whether or not to shift by the mean value. This value is passed through to the StandardScaler class in sklearn.
with_std (bool (optional)) – Whether or not to scale by the standard deviation. This value is passed through to the StandardScaler class in sklearn.
kwargs – Additional keyword argument to pass through to the AbstractFeatureScaler base class.
-
get_config()¶ Generate the configuration necessary for reconstructing the scaler.
- Returns
config – The configuration of the scaler. It should contain all information necessary for reconstructing the scaler using the scaler_from_config function.
- Return type
dict
-
reconstruct(params)¶ Reconstruct the configuration from parameters.
- Parameters
params (dict) – The parameters found in config[“params”] with the config being the dictionary returned by get_config.
-
morphoclass.transforms.scalers.scaler_from_config(config)¶ Reconstruct scaler from a config.
- Parameters
config (dict) – The configuration returned by get_config of a scaler class.
- Returns
obj – The reconstructed scaler.
- Return type
object