Package ai.sklearn4j.preprocessing.data
Class RobustScaler
- java.lang.Object
-
- ai.sklearn4j.base.TransformerMixin<NumpyArray<Double>,NumpyArray<Double>>
-
- ai.sklearn4j.preprocessing.data.RobustScaler
-
public class RobustScaler extends TransformerMixin<NumpyArray<Double>,NumpyArray<Double>>
Scale features using statistics that are robust to outliers. This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile). Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the :meth:`transform` method. Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results. .. versionadded:: 0.17
-
-
Constructor Summary
Constructors Constructor Description RobustScaler()Instantiate a new object of RobustScaler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NumpyArraygetCenter()Gets the The median value for each feature in the training set.String[]getFeatureNamesIn()Gets the Names of features seen during `fit`.longgetNFeaturesIn()Gets the Number of features seen during `fit`.double[]getQuantilesRange()Gets the quantile range used to calculate scale.NumpyArraygetScale()Gets the The (scaled) interquartile range for each feature in the training set.NumpyArray<Double>inverseTransform(NumpyArray<Double> array)Takes a transformed array and reveres the transformation.booleanisUnitVariance()Gets if scale data so that normally distributed features have a variance of 1.booleanisWithCentering()Gets if the transformer centers the data before scaling.booleanisWithScaling()Gets if the transformer scale the data to interquartile range.voidsetCenter(NumpyArray value)Sets the The median value for each feature in the training set.voidsetFeatureNamesIn(String[] value)Sets the Names of features seen during `fit`.voidsetNFeaturesIn(long value)Sets the Number of features seen during `fit`.voidsetQuantilesRange(double[] quantilesRange)Sets the quantile range used to calculate scalevoidsetScale(NumpyArray value)Sets the The (scaled) interquartile range for each feature in the training set.voidsetUnitVariance(boolean unitVariance)Sets if scale data so that normally distributed features have a variance of 1.voidsetWithCentering(boolean withCentering)Sets if the transformer centers the data before scaling.voidsetWithScaling(boolean withScaling)Sets if the transformer scale the data to interquartile range.NumpyArray<Double>transform(NumpyArray<Double> array)Takes the input array and transforms it.
-
-
-
Method Detail
-
setCenter
public void setCenter(NumpyArray value)
Sets the The median value for each feature in the training set.- Parameters:
value- The new value for center.
-
getCenter
public NumpyArray getCenter()
Gets the The median value for each feature in the training set.
-
setScale
public void setScale(NumpyArray value)
Sets the The (scaled) interquartile range for each feature in the training set.- Parameters:
value- The new value for scale.
-
getScale
public NumpyArray getScale()
Gets the The (scaled) interquartile range for each feature in the training set.
-
setNFeaturesIn
public void setNFeaturesIn(long value)
Sets the Number of features seen during `fit`.- Parameters:
value- The new value for nFeaturesIn.
-
getNFeaturesIn
public long getNFeaturesIn()
Gets the Number of features seen during `fit`.
-
setFeatureNamesIn
public void setFeatureNamesIn(String[] value)
Sets the Names of features seen during `fit`. Defined only when `X` has feature names that are all strings.- Parameters:
value- The new value for featureNamesIn.
-
getFeatureNamesIn
public String[] getFeatureNamesIn()
Gets the Names of features seen during `fit`. Defined only when `X` has feature names that are all strings.
-
isWithCentering
public boolean isWithCentering()
Gets if the transformer centers the data before scaling.- Returns:
- If True, center the data before scaling.
-
setWithCentering
public void setWithCentering(boolean withCentering)
Sets if the transformer centers the data before scaling.- Parameters:
withCentering- True for centering before scaling.
-
isWithScaling
public boolean isWithScaling()
Gets if the transformer scale the data to interquartile range.- Returns:
- If True, scale the data to interquartile range.
-
setWithScaling
public void setWithScaling(boolean withScaling)
Sets if the transformer scale the data to interquartile range.- Parameters:
withScaling- True to scale the data to interquartile range.
-
isUnitVariance
public boolean isUnitVariance()
Gets if scale data so that normally distributed features have a variance of 1.- Returns:
- True if scale data so that normally distributed features have a variance of 1, otherwise false.
-
setUnitVariance
public void setUnitVariance(boolean unitVariance)
Sets if scale data so that normally distributed features have a variance of 1.- Parameters:
unitVariance- True to scale, otherwise false.
-
getQuantilesRange
public double[] getQuantilesRange()
Gets the quantile range used to calculate scale.- Returns:
- The rage of the quantile.
-
setQuantilesRange
public void setQuantilesRange(double[] quantilesRange)
Sets the quantile range used to calculate scale- Parameters:
quantilesRange- A double[] array specifying the min and max of the range.
-
transform
public NumpyArray<Double> transform(NumpyArray<Double> array)
Takes the input array and transforms it.- Specified by:
transformin classTransformerMixin<NumpyArray<Double>,NumpyArray<Double>>- Parameters:
array- The array to transform.- Returns:
- The transformed array.
-
inverseTransform
public NumpyArray<Double> inverseTransform(NumpyArray<Double> array)
Takes a transformed array and reveres the transformation.- Specified by:
inverseTransformin classTransformerMixin<NumpyArray<Double>,NumpyArray<Double>>- Parameters:
array- The array to apply reveres transform.- Returns:
- The inversed transform of array.
-
-