Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created June 26, 2019 20:08
Show Gist options
  • Save orcaman/482464156ef5434c0e55a6050878c63e to your computer and use it in GitHub Desktop.
Save orcaman/482464156ef5434c0e55a6050878c63e to your computer and use it in GitHub Desktop.
distnaces.sql
WITH
Distances AS (
SELECT
DISTINCT ML.CENTROID_ID,
sepal_length,
sepal_width,
petal_length,
petal_width,
species,
MIN(NEAREST_CENTROIDS_DISTANCE.DISTANCE) AS distance_from_closest_centroid
FROM
ML.PREDICT(MODEL public.iris_clusters,
(
SELECT
DISTINCT sepal_length,
sepal_width,
petal_length,
petal_width,
species
FROM
`public.iris` )) AS ML
CROSS JOIN
UNNEST(NEAREST_CENTROIDS_DISTANCE) AS NEAREST_CENTROIDS_DISTANCE
GROUP BY
ML.CENTROID_ID,
sepal_length,
sepal_width,
petal_length,
petal_width,
species )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment