public class VectorIndexer extends Estimator<VectorIndexerModel> implements DefaultParamsWritable
Vector
.
This has 2 usage modes: - Automatically identify categorical features (default behavior) - This helps process a dataset of unknown vectors into a dataset with some continuous features and some categorical features. The choice between continuous and categorical is based upon a maxCategories parameter. - Set maxCategories to the maximum number of categorical any categorical feature should have. - E.g.: Feature 0 has unique values {-1.0, 0.0}, and feature 1 values {1.0, 3.0, 5.0}. If maxCategories = 2, then feature 0 will be declared categorical and use indices {0, 1}, and feature 1 will be declared continuous. - Index all features, if all features are categorical - If maxCategories is set to be very large, then this will build an index of unique values for all features. - Warning: This can cause problems if features are continuous since this will collect ALL unique values to the driver. - E.g.: Feature 0 has unique values {-1.0, 0.0}, and feature 1 values {1.0, 3.0, 5.0}. If maxCategories is greater than or equal to 3, then both features will be declared categorical.
This returns a model which can transform categorical features to use 0-based indices.
Index stability: - This is not guaranteed to choose the same category index across multiple runs. - If a categorical feature includes value 0, then this is guaranteed to map value 0 to index 0. This maintains vector sparsity. - More stability may be added in the future.
TODO: Future extensions: The following functionality is planned for the future: - Preserve metadata in transform; if a feature's metadata is already present, do not recompute. - Specify certain features to not index, either via a parameter or via existing metadata. - Add warning if a categorical feature has only 1 category.
Constructor and Description |
---|
VectorIndexer() |
VectorIndexer(String uid) |
Modifier and Type | Method and Description |
---|---|
static Params |
clear(Param<?> param) |
VectorIndexer |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
static String |
explainParam(Param<?> param) |
static String |
explainParams() |
static ParamMap |
extractParamMap() |
static ParamMap |
extractParamMap(ParamMap extra) |
VectorIndexerModel |
fit(Dataset<?> dataset)
Fits a model to the input data.
|
static <T> scala.Option<T> |
get(Param<T> param) |
static <T> scala.Option<T> |
getDefault(Param<T> param) |
static String |
getHandleInvalid() |
static String |
getInputCol() |
static int |
getMaxCategories() |
int |
getMaxCategories() |
static <T> T |
getOrDefault(Param<T> param) |
static String |
getOutputCol() |
static Param<Object> |
getParam(String paramName) |
static Param<String> |
handleInvalid() |
Param<String> |
handleInvalid()
Param for how to handle invalid data (unseen labels or NULL values).
|
static <T> boolean |
hasDefault(Param<T> param) |
static boolean |
hasParam(String paramName) |
static Param<String> |
inputCol() |
static boolean |
isDefined(Param<?> param) |
static boolean |
isSet(Param<?> param) |
static VectorIndexer |
load(String path) |
static IntParam |
maxCategories() |
IntParam |
maxCategories()
Threshold for the number of values a categorical feature can take.
|
static Param<String> |
outputCol() |
static Param<?>[] |
params() |
static void |
save(String path) |
static <T> Params |
set(Param<T> param,
T value) |
VectorIndexer |
setHandleInvalid(String value) |
VectorIndexer |
setInputCol(String value) |
VectorIndexer |
setMaxCategories(int value) |
VectorIndexer |
setOutputCol(String value) |
static String |
toString() |
StructType |
transformSchema(StructType schema)
:: DeveloperApi ::
|
String |
uid()
An immutable unique ID for the object and its derivatives.
|
static MLWriter |
write() |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInputCol, inputCol
getOutputCol, outputCol
getHandleInvalid
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
toString
write
save
initializeLogging, initializeLogIfNecessary, initializeLogIfNecessary, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
public VectorIndexer(String uid)
public VectorIndexer()
public static VectorIndexer load(String path)
public static String toString()
public static Param<?>[] params()
public static String explainParam(Param<?> param)
public static String explainParams()
public static final boolean isSet(Param<?> param)
public static final boolean isDefined(Param<?> param)
public static boolean hasParam(String paramName)
public static Param<Object> getParam(String paramName)
public static final <T> scala.Option<T> get(Param<T> param)
public static final <T> T getOrDefault(Param<T> param)
public static final <T> scala.Option<T> getDefault(Param<T> param)
public static final <T> boolean hasDefault(Param<T> param)
public static final ParamMap extractParamMap()
public static final Param<String> inputCol()
public static final String getInputCol()
public static final Param<String> outputCol()
public static final String getOutputCol()
public static final String getHandleInvalid()
public static Param<String> handleInvalid()
public static IntParam maxCategories()
public static int getMaxCategories()
public static void save(String path) throws java.io.IOException
java.io.IOException
public static MLWriter write()
public String uid()
Identifiable
uid
in interface Identifiable
public VectorIndexer setMaxCategories(int value)
public VectorIndexer setInputCol(String value)
public VectorIndexer setOutputCol(String value)
public VectorIndexer setHandleInvalid(String value)
public VectorIndexerModel fit(Dataset<?> dataset)
Estimator
fit
in class Estimator<VectorIndexerModel>
dataset
- (undocumented)public StructType transformSchema(StructType schema)
PipelineStage
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.
transformSchema
in class PipelineStage
schema
- (undocumented)public VectorIndexer copy(ParamMap extra)
Params
defaultCopy()
.copy
in interface Params
copy
in class Estimator<VectorIndexerModel>
extra
- (undocumented)public Param<String> handleInvalid()
handleInvalid
in interface HasHandleInvalid
public IntParam maxCategories()
(default = 20)
public int getMaxCategories()