-
Notifications
You must be signed in to change notification settings - Fork 29k
[Spark-18080][ML][PYTHON] Python API & Examples for Locality Sensitive Hashing #16715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
85d22c3
cdeca1c
66d308b
d62a2d0
dafc4d1
ac1f4f7
3a21f26
65dab3e
3d3bcf0
69dccde
e7542d0
5cfc9c5
ccabbf4
2508a2f
2dd6aad
8e5468f
6e85e1a
4bc670c
b45ec0a
1b70b91
b1da01e
8f1d708
49edc93
c64d50b
5d55752
d849c3a
36fd9bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ | |
| import org.apache.spark.sql.types.Metadata; | ||
| import org.apache.spark.sql.types.StructField; | ||
| import org.apache.spark.sql.types.StructType; | ||
|
|
||
| import static org.apache.spark.sql.functions.*; | ||
| // $example off$ | ||
|
|
||
| public class JavaMinHashLSHExample { | ||
|
|
@@ -85,8 +87,9 @@ public static void main(String[] args) { | |
| // `model.approxSimilarityJoin(transformedA, transformedB, 0.6)` | ||
| System.out.println("Approximately joining dfA and dfB on Jaccard distance smaller than 0.6:"); | ||
| model.approxSimilarityJoin(dfA, dfB, 0.6) | ||
|
||
| .select("datasetA.id", "datasetB.id", "distCol") | ||
| .show(); | ||
| .select(col("datasetA.id").alias("idA"), | ||
| col("datasetB.id").alias("idB"), | ||
| col("distCol").alias("JaccardDistance")).show(); | ||
|
|
||
| // Compute the locality sensitive hashes for the input rows, then perform approximate nearest | ||
| // neighbor search. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ package org.apache.spark.examples.ml | |
| // $example on$ | ||
| import org.apache.spark.ml.feature.BucketedRandomProjectionLSH | ||
| import org.apache.spark.ml.linalg.Vectors | ||
| import org.apache.spark.sql.functions._ | ||
| // $example off$ | ||
| import org.apache.spark.sql.SparkSession | ||
|
|
||
|
|
@@ -67,8 +68,9 @@ object BucketedRandomProjectionLSHExample { | |
| // `model.approxSimilarityJoin(transformedA, transformedB, 1.5)` | ||
| println("Approximately joining dfA and dfB on Euclidean distance smaller than 1.5:") | ||
| model.approxSimilarityJoin(dfA, dfB, 1.5) | ||
| .select("datasetA.id", "datasetB.id", "distCol") | ||
| .show() | ||
| .select(col("datasetA.id").alias("idA"), | ||
| col("datasetB.id").alias("idB"), | ||
| col("distCol").alias("EuclideanDistance")).show() | ||
|
||
|
|
||
| // Compute the locality sensitive hashes for the input rows, then perform approximate nearest | ||
| // neighbor search. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ package org.apache.spark.examples.ml | |
| // $example on$ | ||
| import org.apache.spark.ml.feature.MinHashLSH | ||
| import org.apache.spark.ml.linalg.Vectors | ||
| import org.apache.spark.sql.functions._ | ||
|
||
| // $example off$ | ||
| import org.apache.spark.sql.SparkSession | ||
|
|
||
|
|
@@ -64,8 +65,9 @@ object MinHashLSHExample { | |
| // `model.approxSimilarityJoin(transformedA, transformedB, 0.6)` | ||
| println("Approximately joining dfA and dfB on Jaccard distance smaller than 0.6:") | ||
| model.approxSimilarityJoin(dfA, dfB, 0.6) | ||
| .select("datasetA.id", "datasetB.id", "distCol") | ||
| .show() | ||
| .select(col("datasetA.id").alias("idA"), | ||
| col("datasetB.id").alias("idB"), | ||
| col("distCol").alias("JaccardDistance")).show() | ||
|
||
|
|
||
| // Compute the locality sensitive hashes for the input rows, then perform approximate nearest | ||
| // neighbor search. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just import
colhere and minhashThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.