public class MinHashLSHModel extends Model<T>
MinHashLSH
, where multiple hash functions are stored. Each hash function
is picked from the following family of hash functions, where a_i and b_i are randomly chosen
integers less than prime:
h_i(x) = ((x \cdot a_i + b_i) \mod prime)
This hash family is approximately min-wise independent according to the reference.
Reference: Tom Bohman, Colin Cooper, and Alan Frieze. "Min-wise independent linear permutations." Electronic Journal of Combinatorics 7 (2000): R26.
param: randCoefficients Pairs of random coefficients. Each pair is used by one hash function.
Modifier and Type | Method and Description |
---|---|
Dataset<?> |
approxNearestNeighbors(Dataset<?> dataset,
Vector key,
int numNearestNeighbors)
Overloaded method for approxNearestNeighbors.
|
Dataset<?> |
approxNearestNeighbors(Dataset<?> dataset,
Vector key,
int numNearestNeighbors,
String distCol)
Given a large dataset and an item, approximately find at most k items which have the closest
distance to the item.
|
Dataset<?> |
approxSimilarityJoin(Dataset<?> datasetA,
Dataset<?> datasetB,
double threshold)
Overloaded method for approxSimilarityJoin.
|
Dataset<?> |
approxSimilarityJoin(Dataset<?> datasetA,
Dataset<?> datasetB,
double threshold,
String distCol)
Join two datasets to approximately find all pairs of rows whose distance are smaller than
the threshold.
|
MinHashLSHModel |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
Param<String> |
inputCol()
Param for input column name.
|
static MinHashLSHModel |
load(String path) |
IntParam |
numHashTables()
Param for the number of hash tables used in LSH OR-amplification.
|
Param<String> |
outputCol()
Param for output column name.
|
static MLReader<MinHashLSHModel> |
read() |
MinHashLSHModel |
setInputCol(String value) |
MinHashLSHModel |
setOutputCol(String value) |
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.
|
MLWriter |
write()
Returns an
MLWriter instance for this ML instance. |
transform, transform, transform
params
getNumHashTables, validateAndTransformSchema
getInputCol
getOutputCol
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
save
$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
public static MLReader<MinHashLSHModel> read()
public static MinHashLSHModel load(String path)
public String uid()
Identifiable
public MinHashLSHModel setInputCol(String value)
public MinHashLSHModel setOutputCol(String value)
public MinHashLSHModel copy(ParamMap extra)
Params
defaultCopy()
.copy
in interface Params
copy
in class Model<MinHashLSHModel>
extra
- (undocumented)public MLWriter write()
MLWritable
MLWriter
instance for this ML instance.public String toString()
toString
in interface Identifiable
toString
in class Object
public Dataset<?> approxNearestNeighbors(Dataset<?> dataset, Vector key, int numNearestNeighbors, String distCol)
outputCol
is missing, the method will transform the data; if
the outputCol
exists, it will use the outputCol
. This allows caching of the
transformed data when necessary.
dataset
- The dataset to search for nearest neighbors of the key.key
- Feature vector representing the item to search for.numNearestNeighbors
- The maximum number of nearest neighbors.distCol
- Output column for storing the distance between each result row and the key.public Dataset<?> approxNearestNeighbors(Dataset<?> dataset, Vector key, int numNearestNeighbors)
dataset
- (undocumented)key
- (undocumented)numNearestNeighbors
- (undocumented)public Dataset<?> approxSimilarityJoin(Dataset<?> datasetA, Dataset<?> datasetB, double threshold, String distCol)
outputCol
is missing, the method will transform the data; if the
outputCol
exists, it will use the outputCol
. This allows caching of the transformed
data when necessary.
datasetA
- One of the datasets to join.datasetB
- Another dataset to join.threshold
- The threshold for the distance of row pairs.distCol
- Output column for storing the distance between each pair of rows.public Dataset<?> approxSimilarityJoin(Dataset<?> datasetA, Dataset<?> datasetB, double threshold)
datasetA
- (undocumented)datasetB
- (undocumented)threshold
- (undocumented)public final Param<String> inputCol()
HasInputCol
inputCol
in interface HasInputCol
public final IntParam numHashTables()
LSHParams
LSH OR-amplification can be used to reduce the false negative rate. Higher values for this param lead to a reduced false negative rate, at the expense of added computational complexity.
numHashTables
in interface LSHParams
public final Param<String> outputCol()
HasOutputCol
outputCol
in interface HasOutputCol
public Dataset<Row> transform(Dataset<?> dataset)
Transformer
transform
in class Transformer
dataset
- (undocumented)public StructType transformSchema(StructType schema)
PipelineStage
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)