make_circles_example


In [ ]:
from cartographer.mapper import Mapper
from cartographer.coverers import HyperRectangleCoverer
from sklearn import datasets
from sklearn.preprocessing import MinMaxScaler
data, labels = datasets.make_circles(n_samples=5000, noise=0.03, factor=0.3)

params = {'coverer__intervals' :10,
          'coverer__overlap' : 0.1,
          'clusterer__min_samples' : 3,
          'clusterer__eps': 0.5}
m = Mapper(params=params)

scaled_data = MinMaxScaler().fit_transform(data)
m.fit(data,scaled_data)

In [ ]:
from cartographer.visualization import html_graph
from IPython.core.display import HTML
HTML(html_graph(m,
                {"labels":labels},
                {"y[0]" : scaled_data[:,0],
                 "y[1]" : scaled_data[:,1]}))

In [ ]:
%matplotlib inline

import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.pyplot import cm 
import numpy as np


fig = plt.figure(figsize=(20,20))

ax = fig.add_subplot(111, aspect='equal')
ax.axes.set_xlim([-0.2,1.2])
ax.axes.set_ylim([-0.2,1.2])

color=iter(cm.rainbow(np.linspace(0,1,m.coverer.lowerbounds.shape[0])))

for lb, up in zip(m.coverer.lowerbounds,m.coverer.upperbounds):
    c=next(color)
    ax.add_patch(patches.Rectangle(lb,*(up-lb),fill=False, edgecolor=c))

ax.plot(scaled_data[:,0],scaled_data[:,1],".");