Skip to content

Instantly share code, notes, and snippets.

@WoolDoughnut310
Created October 28, 2022 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WoolDoughnut310/d33f859d6b962465ae8d42d1eb6bd4ca to your computer and use it in GitHub Desktop.
Save WoolDoughnut310/d33f859d6b962465ae8d42d1eb6bd4ca to your computer and use it in GitHub Desktop.
import * as tf from "@tensorflow/tfjs-node"
import { KMeans, setBackend } from "scikitjs"
setBackend(tf)
const train = [
[1, 2],
[1, 4],
[4, 4],
[4, 0]
]
const kmean = new KMeans({ nClusters: 2 })
kmean.fit(train)
const test = [
[3, 2],
[2, 1]
]
const result = kmean.predict(test)
console.log(result.array())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment