StringIndexerModel (Spark 3.5.5 JavaDoc) (original) (raw)
Object
- org.apache.spark.ml.PipelineStage
- org.apache.spark.ml.Transformer
- org.apache.spark.ml.Model<StringIndexerModel>
* * org.apache.spark.ml.feature.StringIndexerModel
- org.apache.spark.ml.Model<StringIndexerModel>
- org.apache.spark.ml.Transformer
All Implemented Interfaces:
java.io.Serializable, org.apache.spark.internal.Logging, StringIndexerBase, Params, HasHandleInvalid, HasInputCol, HasInputCols, HasOutputCol, HasOutputCols, Identifiable, MLWritable
public class StringIndexerModel
extends Model<StringIndexerModel>
implements StringIndexerBase, MLWritable
Model fitted by StringIndexer.
param: labelsArray Array of ordered list of labels, corresponding to indices to be assigned for each input column.
See Also:
Serialized Form
Note:
During transformation, if any input column does not exist,StringIndexerModel.transform
would skip the input column. If all input columns do not exist, it returns the input dataset unmodified. This is a temporary fix for the case when target labels do not exist during prediction.
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 StringIndexerModel(String[] labels) StringIndexerModel(String[][] labelsArray) StringIndexerModel(String uid, String[] labels) StringIndexerModel(String uid, String[][] labelsArray) Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
Modifier and Type Method and Description StringIndexerModel copy(ParamMap extra) Creates a copy of this instance with the same UID and some extra params. Param handleInvalid() Param for how to handle invalid data (unseen labels or NULL values). Param inputCol() Param for input column name. StringArrayParam inputCols() Param for input column names. String[] labels() Deprecated. String[][] labelsArray() static StringIndexerModel load(String path) Param outputCol() Param for output column name. StringArrayParam outputCols() Param for output column names. static MLReader<StringIndexerModel> read() StringIndexerModel setHandleInvalid(String value) StringIndexerModel setInputCol(String value) StringIndexerModel setInputCols(String[] value) StringIndexerModel setOutputCol(String value) StringIndexerModel setOutputCols(String[] value) Param stringOrderType() Param for how to order labels of string column. String toString() Dataset<Row> transform(Dataset<?> dataset) Transforms the input dataset. 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. org.apache.spark.ml.feature.StringIndexerModel.StringIndexModelWriter write() Returns an MLWriter instance for this ML instance. * ### Methods inherited from class org.apache.spark.ml.[Model](../../../../../org/apache/spark/ml/Model.html "class in org.apache.spark.ml") `[hasParent](../../../../../org/apache/spark/ml/Model.html#hasParent--), [parent](../../../../../org/apache/spark/ml/Model.html#parent--), [setParent](../../../../../org/apache/spark/ml/Model.html#setParent-org.apache.spark.ml.Estimator-)` * ### Methods inherited from class org.apache.spark.ml.[Transformer](../../../../../org/apache/spark/ml/Transformer.html "class in org.apache.spark.ml") `[transform](../../../../../org/apache/spark/ml/Transformer.html#transform-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamMap-), [transform](../../../../../org/apache/spark/ml/Transformer.html#transform-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamPair-org.apache.spark.ml.param.ParamPair...-), [transform](../../../../../org/apache/spark/ml/Transformer.html#transform-org.apache.spark.sql.Dataset-org.apache.spark.ml.param.ParamPair-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, wait, wait, wait` * ### Methods inherited from interface org.apache.spark.ml.feature.[StringIndexerBase](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html "interface in org.apache.spark.ml.feature") `[getInOutCols](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#getInOutCols--), [getStringOrderType](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#getStringOrderType--), [validateAndTransformField](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#validateAndTransformField-org.apache.spark.sql.types.StructType-java.lang.String-java.lang.String-), [validateAndTransformSchema](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#validateAndTransformSchema-org.apache.spark.sql.types.StructType-boolean-)` * ### Methods inherited from interface org.apache.spark.ml.param.shared.[HasHandleInvalid](../../../../../org/apache/spark/ml/param/shared/HasHandleInvalid.html "interface in org.apache.spark.ml.param.shared") `[getHandleInvalid](../../../../../org/apache/spark/ml/param/shared/HasHandleInvalid.html#getHandleInvalid--)` * ### 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.[HasInputCols](../../../../../org/apache/spark/ml/param/shared/HasInputCols.html "interface in org.apache.spark.ml.param.shared") `[getInputCols](../../../../../org/apache/spark/ml/param/shared/HasInputCols.html#getInputCols--)` * ### Methods inherited from interface org.apache.spark.ml.param.shared.[HasOutputCols](../../../../../org/apache/spark/ml/param/shared/HasOutputCols.html "interface in org.apache.spark.ml.param.shared") `[getOutputCols](../../../../../org/apache/spark/ml/param/shared/HasOutputCols.html#getOutputCols--)` * ### 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.[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
* #### StringIndexerModel public StringIndexerModel(String uid, String[][] labelsArray) * #### StringIndexerModel public StringIndexerModel(String uid, String[] labels) * #### StringIndexerModel public StringIndexerModel(String[] labels) * #### StringIndexerModel public StringIndexerModel(String[][] labelsArray)
Method Detail
* #### read public static [MLReader](../../../../../org/apache/spark/ml/util/MLReader.html "class in org.apache.spark.ml.util")<[StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature")> read() * #### load public static [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") load(String path) * #### handleInvalid public [Param](../../../../../org/apache/spark/ml/param/Param.html "class in org.apache.spark.ml.param")<String> handleInvalid() Param for how to handle invalid data (unseen labels or NULL values). Options are 'skip' (filter out rows with invalid data), 'error' (throw an error), or 'keep' (put invalid data in a special additional bucket, at index numLabels). Default: "error" Specified by: `[handleInvalid](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#handleInvalid--)` in interface `[StringIndexerBase](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html "interface in org.apache.spark.ml.feature")` Specified by: `[handleInvalid](../../../../../org/apache/spark/ml/param/shared/HasHandleInvalid.html#handleInvalid--)` in interface `[HasHandleInvalid](../../../../../org/apache/spark/ml/param/shared/HasHandleInvalid.html "interface in org.apache.spark.ml.param.shared")` Returns: (undocumented) * #### stringOrderType public final [Param](../../../../../org/apache/spark/ml/param/Param.html "class in org.apache.spark.ml.param")<String> stringOrderType() Param for how to order labels of string column. The first label after ordering is assigned an index of 0\. Options are: - 'frequencyDesc': descending order by label frequency (most frequent label assigned 0) - 'frequencyAsc': ascending order by label frequency (least frequent label assigned 0) - 'alphabetDesc': descending alphabetical order - 'alphabetAsc': ascending alphabetical order Default is 'frequencyDesc'. Note: In case of equal frequency when under frequencyDesc/Asc, the strings are further sorted alphabetically. Specified by: `[stringOrderType](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html#stringOrderType--)` in interface `[StringIndexerBase](../../../../../org/apache/spark/ml/feature/StringIndexerBase.html "interface in org.apache.spark.ml.feature")` Returns: (undocumented) * #### outputCols public final [StringArrayParam](../../../../../org/apache/spark/ml/param/StringArrayParam.html "class in org.apache.spark.ml.param") outputCols() Param for output column names. Specified by: `[outputCols](../../../../../org/apache/spark/ml/param/shared/HasOutputCols.html#outputCols--)` in interface `[HasOutputCols](../../../../../org/apache/spark/ml/param/shared/HasOutputCols.html "interface in org.apache.spark.ml.param.shared")` Returns: (undocumented) * #### inputCols public final [StringArrayParam](../../../../../org/apache/spark/ml/param/StringArrayParam.html "class in org.apache.spark.ml.param") inputCols() Param for input column names. Specified by: `[inputCols](../../../../../org/apache/spark/ml/param/shared/HasInputCols.html#inputCols--)` in interface `[HasInputCols](../../../../../org/apache/spark/ml/param/shared/HasInputCols.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) * #### labelsArray public String[][] labelsArray() * #### labels public String[] labels() Deprecated. * #### setHandleInvalid public [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") setHandleInvalid(String value) * #### setInputCol public [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") setInputCol(String value) * #### setOutputCol public [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") setOutputCol(String value) * #### setInputCols public [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") setInputCols(String[] value) * #### setOutputCols public [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature") setOutputCols(String[] value) * #### transform public [Dataset](../../../../../org/apache/spark/sql/Dataset.html "class in org.apache.spark.sql")<[Row](../../../../../org/apache/spark/sql/Row.html "interface in org.apache.spark.sql")> transform([Dataset](../../../../../org/apache/spark/sql/Dataset.html "class in org.apache.spark.sql")<?> dataset) Transforms the input dataset. Specified by: `[transform](../../../../../org/apache/spark/ml/Transformer.html#transform-org.apache.spark.sql.Dataset-)` in class `[Transformer](../../../../../org/apache/spark/ml/Transformer.html "class in org.apache.spark.ml")` 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 [StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.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/Model.html#copy-org.apache.spark.ml.param.ParamMap-)` in class `[Model](../../../../../org/apache/spark/ml/Model.html "class in org.apache.spark.ml")<[StringIndexerModel](../../../../../org/apache/spark/ml/feature/StringIndexerModel.html "class in org.apache.spark.ml.feature")>` Parameters: `extra` \- (undocumented) Returns: (undocumented) * #### write public org.apache.spark.ml.feature.StringIndexerModel.StringIndexModelWriter write() Description copied from interface: `[MLWritable](../../../../../org/apache/spark/ml/util/MLWritable.html#write--)` Returns an `MLWriter` instance for this ML instance. Specified by: `[write](../../../../../org/apache/spark/ml/util/MLWritable.html#write--)` in interface `[MLWritable](../../../../../org/apache/spark/ml/util/MLWritable.html "interface in org.apache.spark.ml.util")` Returns: (undocumented) * #### toString public String toString() Specified by: `[toString](../../../../../org/apache/spark/ml/util/Identifiable.html#toString--)` in interface `[Identifiable](../../../../../org/apache/spark/ml/util/Identifiable.html "interface in org.apache.spark.ml.util")` Overrides: `toString` in class `Object`