Author - Mohit Rathore mrmohitrathoremr@gmail.com - markroxor.in
Licensed under The MIT License - https://opensource.org/licenses/MIT

In [1]:
import numpy as np

from fromscratchtoml.toolbox import binary_visualize
from fromscratchtoml.toolbox.random import Distribution

from sklearn.datasets import load_iris

from fromscratchtoml.cluster import DBSCAN

%matplotlib inline

DBSCAN - Density-based spatial clustering of applications with noise

In [2]:
eps = 0.5
min_points = 5

X = load_iris().data
In [ ]:
 
In [3]:
db = DBSCAN(eps, min_points)
In [4]:
db.fit(X)
Out[4]:
DBSCAN({'eps': 0.5, 'min_neigh': 5})
In [ ]:
 
In [5]:
binary_visualize(X[:, :2], db.clan)

Classifying against custom data

In [6]:
x1 = Distribution.linear(pts=10, mean=[0, 20])
y1 = np.ones([len(x1), 1])

x2 = Distribution.linear(pts=10, mean=[0, 0])
y2 = -np.ones([len(x2), 1])

x3 = Distribution.linear(pts=10, mean=[2, 10])
y3 = 2*np.ones([len(x3), 1])

X = np.vstack([x1, x2, x3])
Y = np.vstack([y1, y2, y3])
In [7]:
eps = 2
min_points = 2
In [ ]:
 
In [8]:
db = DBSCAN(eps, min_points)
db.fit(X)
Out[8]:
DBSCAN({'eps': 2, 'min_neigh': 2})
In [9]:
binary_visualize(X, db.clan)
In [ ]:
 
In [ ]: