Class MinHashLSHModel

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, LSHParams, Params, HasInputCol, HasOutputCol, Identifiable, MLWritable, scala.Serializable

public class MinHashLSHModel extends Model<T>
Model produced by 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.

See Also:
  • Method Details

    • read

      public static MLReader<MinHashLSHModel> read()
    • load

      public static MinHashLSHModel load(String path)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Returns:
      (undocumented)
    • setInputCol

      public MinHashLSHModel setInputCol(String value)
    • setOutputCol

      public MinHashLSHModel setOutputCol(String value)
    • copy

      public MinHashLSHModel copy(ParamMap extra)
      Description copied from interface: Params
      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 in interface Params
      Specified by:
      copy in class Model<MinHashLSHModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • write

      public MLWriter write()
      Description copied from interface: MLWritable
      Returns an MLWriter instance for this ML instance.
      Returns:
      (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      Overrides:
      toString in class Object
    • approxNearestNeighbors

      public 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. If the HasOutputCol.outputCol() is missing, the method will transform the data; if the HasOutputCol.outputCol() exists, it will use the HasOutputCol.outputCol(). This allows caching of the transformed data when necessary.

      Parameters:
      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.
      Returns:
      A dataset containing at most k items closest to the key. A column "distCol" is added to show the distance between each row and the key.
      Note:
      This method is experimental and will likely change behavior in the next release.

    • approxNearestNeighbors

      public Dataset<?> approxNearestNeighbors(Dataset<?> dataset, Vector key, int numNearestNeighbors)
      Overloaded method for approxNearestNeighbors. Use "distCol" as default distCol.
      Parameters:
      dataset - (undocumented)
      key - (undocumented)
      numNearestNeighbors - (undocumented)
      Returns:
      (undocumented)
    • approxSimilarityJoin

      public 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. If the HasOutputCol.outputCol() is missing, the method will transform the data; if the HasOutputCol.outputCol() exists, it will use the HasOutputCol.outputCol(). This allows caching of the transformed data when necessary.

      Parameters:
      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.
      Returns:
      A joined dataset containing pairs of rows. The original rows are in columns "datasetA" and "datasetB", and a column "distCol" is added to show the distance between each pair.
    • approxSimilarityJoin

      public Dataset<?> approxSimilarityJoin(Dataset<?> datasetA, Dataset<?> datasetB, double threshold)
      Overloaded method for approxSimilarityJoin. Use "distCol" as default distCol.
      Parameters:
      datasetA - (undocumented)
      datasetB - (undocumented)
      threshold - (undocumented)
      Returns:
      (undocumented)
    • inputCol

      public final Param<String> inputCol()
      Description copied from interface: HasInputCol
      Param for input column name.
      Specified by:
      inputCol in interface HasInputCol
      Returns:
      (undocumented)
    • numHashTables

      public final IntParam numHashTables()
      Description copied from interface: LSHParams
      Param for the number of hash tables used in LSH OR-amplification.

      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.

      Specified by:
      numHashTables in interface LSHParams
      Returns:
      (undocumented)
    • outputCol

      public final Param<String> outputCol()
      Description copied from interface: HasOutputCol
      Param for output column name.
      Specified by:
      outputCol in interface HasOutputCol
      Returns:
      (undocumented)
    • transform

      public Dataset<Row> transform(Dataset<?> dataset)
      Description copied from class: Transformer
      Transforms the input dataset.
      Specified by:
      transform in class Transformer
      Parameters:
      dataset - (undocumented)
      Returns:
      (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: 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.

      Specified by:
      transformSchema in class PipelineStage
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)