TF-KMeans
Description
A Simple JavaScript Library to make it easy for people to use KMeans algorithms with Tensorflow JS.
The library was born out of another project in which except KMeans, our code completely depended on TF.JS
As such, moving to TF.JS helped standardise our code base substantially and reduce dependency on other libraries
Sample Code
const KMeans = ; const tf = ; const kmeans = k: 2 maxIter: 30 distanceFunction: KMeansdefaultEuclideanDistance ; const dataset = tf; const predictions = kmeans; console; console; console; kmeans;
You can use the Asynchronous TrainAsync if you want to use an asynchronous callback function
const kmeans = k: 3 maxIter: 30 distanceFunction: KMeansdefaultEuclideanDistance ; const dataset = tf; console; const predictions = await kmeans;
Functions
-
Constructor
Takes 3 Optional parameters
- k:- Number of Clusters
- maxIter:- Max Iterations
- distanceFunction:- The Distance function Used Currently only Eucledian Distance Provided
-
Train
Takes Dataset as Parameter
Performs Training on This Dataset
Sync callback function is optional
-
TrainAsync
Takes Dataset as Parameter
Performs Training on This Dataset
Also takes async callback function called at the end of every iteration
-
Centroids
Returns the Centroids found for the dataset on which KMeans was Trained
-
Predict
Performs Predictions on the data Provided as Input
PEER DEPENDENCIES
Typings
As the code is originally written in TypeScript, Type Support is provided out of the box
Contact Me
You could contact me via LinkedIn You could file issues or add features via Pull Requests on GitHub