Author - Mohit Rathore mrmohitrathoremr@gmail.com - markroxor.in
Licensed under The MIT License - https://opensource.org/licenses/MIT
import numpy as np
from fromscratchtoml.toolbox import binary_visualize
from fromscratchtoml.cluster import KMeans as KMeans
from fromscratchtoml.toolbox.random import Distribution
%matplotlib inline
X1 = Distribution.linear(pts=500, covr=[[1.2, -1],[-1, 1]], mean=[0, 0])
X2 = Distribution.linear(pts=500, covr=[[1.2, -1],[-1, 1]], mean=[-1, -2])
X3 = Distribution.linear(pts=500, covr=[[1.2, -1],[-1, 1]], mean=[6, -3])
X = np.vstack([X1, X2, X3])
y_pred = KMeans(n_clusters=3).fit_predict(X)
binary_visualize(X, y_pred)
X1 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[0, 0])
X2 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[-0, -3])
X3 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[6, -3])
X = np.vstack([X1, X2, X3])
y_pred = KMeans(n_clusters=3).fit_predict(X)
binary_visualize(X, y_pred)
X1 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[0, 0])
X2 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[0, -6])
X3 = Distribution.linear(pts=500, covr=[[0, -1],[-1, 0]], mean=[6, -3])
X = np.vstack([X1, X2, X3])
km = KMeans(n_clusters=3)
km.fit(X)
binary_visualize(X, km.labels)
km = KMeans(n_clusters=100)
km.fit(X)
binary_visualize(X, km.labels)
km = KMeans(n_clusters=10)
km.fit(X)
binary_visualize(X, km.labels)