RobustScaler (Spark 3.5.5 JavaDoc) (original) (raw)
Object
- org.apache.spark.ml.PipelineStage
- org.apache.spark.ml.Estimator<RobustScalerModel>
- org.apache.spark.ml.feature.RobustScaler
- org.apache.spark.ml.Estimator<RobustScalerModel>
All Implemented Interfaces:
java.io.Serializable, org.apache.spark.internal.Logging, RobustScalerParams, Params, HasInputCol, HasOutputCol, HasRelativeError, DefaultParamsWritable, Identifiable, MLWritable
public class RobustScaler
extends Estimator<RobustScalerModel>
implements RobustScalerParams, DefaultParamsWritable
Scale features using statistics that are robust to outliers. RobustScaler removes the median and scales the data according to the quantile range. The quantile range is by default IQR (Interquartile Range, quantile range between the 1st quartile = 25th quantile and the 3rd quartile = 75th quantile) but can be configured. Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and quantile range are then stored to be used on later data using the 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 quantile range often give better results. Note that NaN values are ignored in the computation of medians and ranges.
See Also:
Serialized Form
Nested Class Summary
* ### Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging `org.apache.spark.internal.Logging.SparkShellLoggingFilter`
Constructor Summary
Constructors
Constructor and Description RobustScaler() RobustScaler(String uid) Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method and Description RobustScaler copy(ParamMap extra) Creates a copy of this instance with the same UID and some extra params. RobustScalerModel fit(Dataset<?> dataset) Fits a model to the input data. Param inputCol() Param for input column name. static RobustScaler load(String path) DoubleParam lower() Lower quantile to calculate quantile range, shared by all features Default: 0.25 Param outputCol() Param for output column name. static MLReader read() DoubleParam relativeError() Param for the relative target precision for the approximate quantile algorithm. RobustScaler setInputCol(String value) RobustScaler setLower(double value) RobustScaler setOutputCol(String value) RobustScaler setRelativeError(double value) RobustScaler setUpper(double value) RobustScaler setWithCentering(boolean value) RobustScaler setWithScaling(boolean value) StructType transformSchema(StructType schema) Check transform validity and derive the output schema from the input schema. String uid() An immutable unique ID for the object and its derivatives. DoubleParam upper() Upper quantile to calculate quantile range, shared by all features Default: 0.75 BooleanParam withCentering() Whether to center the data with median before scaling. BooleanParam withScaling() Whether to scale the data to quantile range. * ### Methods inherited from class org.apache.spark.ml.[Estimator](../../../../../org/apache/spark/ml/Estimator.html "class in org.apache.spark.ml") `[fit](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamMap-), [fit](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamPair-org.apache.spark.ml.param.ParamPair...-), [fit](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamPair-scala.collection.Seq-), [fit](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-scala.collection.Seq-)` * ### Methods inherited from class org.apache.spark.ml.[PipelineStage](../../../../../org/apache/spark/ml/PipelineStage.html "class in org.apache.spark.ml") `[params](../../../../../org/apache/spark/ml/PipelineStage.html#params--)` * ### Methods inherited from class Object `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait` * ### Methods inherited from interface org.apache.spark.ml.feature.[RobustScalerParams](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html "interface in org.apache.spark.ml.feature") `[getLower](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#getLower--), [getUpper](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#getUpper--), [getWithCentering](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#getWithCentering--), [getWithScaling](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#getWithScaling--), [validateAndTransformSchema](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#validateAndTransformSchema-org.apache.spark.sql.types.StructType-)` * ### Methods inherited from interface org.apache.spark.ml.param.shared.[HasInputCol](../../../../../org/apache/spark/ml/param/shared/HasInputCol.html "interface in org.apache.spark.ml.param.shared") `[getInputCol](../../../../../org/apache/spark/ml/param/shared/HasInputCol.html#getInputCol--)` * ### Methods inherited from interface org.apache.spark.ml.param.shared.[HasOutputCol](../../../../../org/apache/spark/ml/param/shared/HasOutputCol.html "interface in org.apache.spark.ml.param.shared") `[getOutputCol](../../../../../org/apache/spark/ml/param/shared/HasOutputCol.html#getOutputCol--)` * ### Methods inherited from interface org.apache.spark.ml.param.shared.[HasRelativeError](../../../../../org/apache/spark/ml/param/shared/HasRelativeError.html "interface in org.apache.spark.ml.param.shared") `[getRelativeError](../../../../../org/apache/spark/ml/param/shared/HasRelativeError.html#getRelativeError--)` * ### Methods inherited from interface org.apache.spark.ml.param.[Params](../../../../../org/apache/spark/ml/param/Params.html "interface in org.apache.spark.ml.param") `[clear](../../../../../org/apache/spark/ml/param/Params.html#clear-org.apache.spark.ml.param.Param-), [copyValues](../../../../../org/apache/spark/ml/param/Params.html#copyValues-T-org.apache.spark.ml.param.ParamMap-), [defaultCopy](../../../../../org/apache/spark/ml/param/Params.html#defaultCopy-org.apache.spark.ml.param.ParamMap-), [defaultParamMap](../../../../../org/apache/spark/ml/param/Params.html#defaultParamMap--), [explainParam](../../../../../org/apache/spark/ml/param/Params.html#explainParam-org.apache.spark.ml.param.Param-), [explainParams](../../../../../org/apache/spark/ml/param/Params.html#explainParams--), [extractParamMap](../../../../../org/apache/spark/ml/param/Params.html#extractParamMap--), [extractParamMap](../../../../../org/apache/spark/ml/param/Params.html#extractParamMap-org.apache.spark.ml.param.ParamMap-), [get](../../../../../org/apache/spark/ml/param/Params.html#get-org.apache.spark.ml.param.Param-), [getDefault](../../../../../org/apache/spark/ml/param/Params.html#getDefault-org.apache.spark.ml.param.Param-), [getOrDefault](../../../../../org/apache/spark/ml/param/Params.html#getOrDefault-org.apache.spark.ml.param.Param-), [getParam](../../../../../org/apache/spark/ml/param/Params.html#getParam-java.lang.String-), [hasDefault](../../../../../org/apache/spark/ml/param/Params.html#hasDefault-org.apache.spark.ml.param.Param-), [hasParam](../../../../../org/apache/spark/ml/param/Params.html#hasParam-java.lang.String-), [isDefined](../../../../../org/apache/spark/ml/param/Params.html#isDefined-org.apache.spark.ml.param.Param-), [isSet](../../../../../org/apache/spark/ml/param/Params.html#isSet-org.apache.spark.ml.param.Param-), [onParamChange](../../../../../org/apache/spark/ml/param/Params.html#onParamChange-org.apache.spark.ml.param.Param-), [paramMap](../../../../../org/apache/spark/ml/param/Params.html#paramMap--), [params](../../../../../org/apache/spark/ml/param/Params.html#params--), [set](../../../../../org/apache/spark/ml/param/Params.html#set-org.apache.spark.ml.param.Param-T-), [set](../../../../../org/apache/spark/ml/param/Params.html#set-org.apache.spark.ml.param.ParamPair-), [set](../../../../../org/apache/spark/ml/param/Params.html#set-java.lang.String-java.lang.Object-), [setDefault](../../../../../org/apache/spark/ml/param/Params.html#setDefault-org.apache.spark.ml.param.Param-T-), [setDefault](../../../../../org/apache/spark/ml/param/Params.html#setDefault-scala.collection.Seq-), [shouldOwn](../../../../../org/apache/spark/ml/param/Params.html#shouldOwn-org.apache.spark.ml.param.Param-)` * ### Methods inherited from interface org.apache.spark.ml.util.[Identifiable](../../../../../org/apache/spark/ml/util/Identifiable.html "interface in org.apache.spark.ml.util") `[toString](../../../../../org/apache/spark/ml/util/Identifiable.html#toString--)` * ### Methods inherited from interface org.apache.spark.ml.util.[DefaultParamsWritable](../../../../../org/apache/spark/ml/util/DefaultParamsWritable.html "interface in org.apache.spark.ml.util") `[write](../../../../../org/apache/spark/ml/util/DefaultParamsWritable.html#write--)` * ### Methods inherited from interface org.apache.spark.ml.util.[MLWritable](../../../../../org/apache/spark/ml/util/MLWritable.html "interface in org.apache.spark.ml.util") `[save](../../../../../org/apache/spark/ml/util/MLWritable.html#save-java.lang.String-)` * ### Methods inherited from interface org.apache.spark.internal.Logging `$init$, initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, initLock, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log__$eq, org$apache$spark$internal$Logging$$log_, uninitialize`
Constructor Detail
* #### RobustScaler public RobustScaler(String uid) * #### RobustScaler public RobustScaler()
Method Detail
* #### load public static [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") load(String path) * #### read public static [MLReader](../../../../../org/apache/spark/ml/util/MLReader.html "class in org.apache.spark.ml.util")<T> read() * #### lower public [DoubleParam](../../../../../org/apache/spark/ml/param/DoubleParam.html "class in org.apache.spark.ml.param") lower() Lower quantile to calculate quantile range, shared by all features Default: 0.25 Specified by: `[lower](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#lower--)` in interface `[RobustScalerParams](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html "interface in org.apache.spark.ml.feature")` Returns: (undocumented) * #### upper public [DoubleParam](../../../../../org/apache/spark/ml/param/DoubleParam.html "class in org.apache.spark.ml.param") upper() Upper quantile to calculate quantile range, shared by all features Default: 0.75 Specified by: `[upper](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#upper--)` in interface `[RobustScalerParams](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html "interface in org.apache.spark.ml.feature")` Returns: (undocumented) * #### withCentering public [BooleanParam](../../../../../org/apache/spark/ml/param/BooleanParam.html "class in org.apache.spark.ml.param") withCentering() Whether to center the data with median before scaling. It will build a dense output, so take care when applying to sparse input. Default: false Specified by: `[withCentering](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#withCentering--)` in interface `[RobustScalerParams](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html "interface in org.apache.spark.ml.feature")` Returns: (undocumented) * #### withScaling public [BooleanParam](../../../../../org/apache/spark/ml/param/BooleanParam.html "class in org.apache.spark.ml.param") withScaling() Whether to scale the data to quantile range. Default: true Specified by: `[withScaling](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html#withScaling--)` in interface `[RobustScalerParams](../../../../../org/apache/spark/ml/feature/RobustScalerParams.html "interface in org.apache.spark.ml.feature")` Returns: (undocumented) * #### relativeError public final [DoubleParam](../../../../../org/apache/spark/ml/param/DoubleParam.html "class in org.apache.spark.ml.param") relativeError() Param for the relative target precision for the approximate quantile algorithm. Must be in the range \[0, 1\]. Specified by: `[relativeError](../../../../../org/apache/spark/ml/param/shared/HasRelativeError.html#relativeError--)` in interface `[HasRelativeError](../../../../../org/apache/spark/ml/param/shared/HasRelativeError.html "interface in org.apache.spark.ml.param.shared")` Returns: (undocumented) * #### outputCol public final [Param](../../../../../org/apache/spark/ml/param/Param.html "class in org.apache.spark.ml.param")<String> outputCol() Param for output column name. Specified by: `[outputCol](../../../../../org/apache/spark/ml/param/shared/HasOutputCol.html#outputCol--)` in interface `[HasOutputCol](../../../../../org/apache/spark/ml/param/shared/HasOutputCol.html "interface in org.apache.spark.ml.param.shared")` Returns: (undocumented) * #### inputCol public final [Param](../../../../../org/apache/spark/ml/param/Param.html "class in org.apache.spark.ml.param")<String> inputCol() Description copied from interface: `[HasInputCol](../../../../../org/apache/spark/ml/param/shared/HasInputCol.html#inputCol--)` Param for input column name. Specified by: `[inputCol](../../../../../org/apache/spark/ml/param/shared/HasInputCol.html#inputCol--)` in interface `[HasInputCol](../../../../../org/apache/spark/ml/param/shared/HasInputCol.html "interface in org.apache.spark.ml.param.shared")` Returns: (undocumented) * #### uid public String uid() An immutable unique ID for the object and its derivatives. Specified by: `[uid](../../../../../org/apache/spark/ml/util/Identifiable.html#uid--)` in interface `[Identifiable](../../../../../org/apache/spark/ml/util/Identifiable.html "interface in org.apache.spark.ml.util")` Returns: (undocumented) * #### setInputCol public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setInputCol(String value) * #### setOutputCol public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setOutputCol(String value) * #### setLower public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setLower(double value) * #### setUpper public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setUpper(double value) * #### setWithCentering public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setWithCentering(boolean value) * #### setWithScaling public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setWithScaling(boolean value) * #### setRelativeError public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") setRelativeError(double value) * #### fit public [RobustScalerModel](../../../../../org/apache/spark/ml/feature/RobustScalerModel.html "class in org.apache.spark.ml.feature") fit([Dataset](../../../../../org/apache/spark/sql/Dataset.html "class in org.apache.spark.sql")<?> dataset) Description copied from class: `[Estimator](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-)` Fits a model to the input data. Specified by: `[fit](../../../../../org/apache/spark/ml/Estimator.html#fit-org.apache.spark.sql.Dataset-)` in class `[Estimator](../../../../../org/apache/spark/ml/Estimator.html "class in org.apache.spark.ml")<[RobustScalerModel](../../../../../org/apache/spark/ml/feature/RobustScalerModel.html "class in org.apache.spark.ml.feature")>` Parameters: `dataset` \- (undocumented) Returns: (undocumented) * #### transformSchema public [StructType](../../../../../org/apache/spark/sql/types/StructType.html "class in org.apache.spark.sql.types") transformSchema([StructType](../../../../../org/apache/spark/sql/types/StructType.html "class in org.apache.spark.sql.types") schema) Check transform validity and derive the output schema from the input schema. We check validity for interactions between parameters during `transformSchema` and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by `Param.validate()`. Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks. Specified by: `[transformSchema](../../../../../org/apache/spark/ml/PipelineStage.html#transformSchema-org.apache.spark.sql.types.StructType-)` in class `[PipelineStage](../../../../../org/apache/spark/ml/PipelineStage.html "class in org.apache.spark.ml")` Parameters: `schema` \- (undocumented) Returns: (undocumented) * #### copy public [RobustScaler](../../../../../org/apache/spark/ml/feature/RobustScaler.html "class in org.apache.spark.ml.feature") copy([ParamMap](../../../../../org/apache/spark/ml/param/ParamMap.html "class in org.apache.spark.ml.param") extra) Description copied from interface: `[Params](../../../../../org/apache/spark/ml/param/Params.html#copy-org.apache.spark.ml.param.ParamMap-)` Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See `defaultCopy()`. Specified by: `[copy](../../../../../org/apache/spark/ml/param/Params.html#copy-org.apache.spark.ml.param.ParamMap-)` in interface `[Params](../../../../../org/apache/spark/ml/param/Params.html "interface in org.apache.spark.ml.param")` Specified by: `[copy](../../../../../org/apache/spark/ml/Estimator.html#copy-org.apache.spark.ml.param.ParamMap-)` in class `[Estimator](../../../../../org/apache/spark/ml/Estimator.html "class in org.apache.spark.ml")<[RobustScalerModel](../../../../../org/apache/spark/ml/feature/RobustScalerModel.html "class in org.apache.spark.ml.feature")>` Parameters: `extra` \- (undocumented) Returns: (undocumented)