Basic Usage of tmap

import sklearn

import plotly.plotly as py
import plotly.graph_objs as go

import matplotlib.pyplot as plt
import numpy as np

from sklearn.cluster import DBSCAN
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import StandardScaler




###################################
# Load libraries
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import DBSCAN
from sklearn.preprocessing import MinMaxScaler

###################################



shenzy@SZYENVS:~/software/tmap$ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from sklearn import datasets
>>> import pandas as pd
>>> import sklearn
>>> from sklearn import datasets
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.cluster import DBSCAN
>>> from sklearn.preprocessing import MinMaxScaler
>>> iris = datasets.load_iris()
>>> X = iris.data
>>> X = pd.DataFrame(X,columns = iris.feature_names)
>>> from tmap.tda import mapper, filter
>>> from tmap.tda.cover import Cover
>>> # Step1. initiate a Mapper
... tm = mapper.Mapper(verbose=1)
>>> 
>>> # Step2. Projection
... lens = [filter.MDS(components=[0, 1])]
>>> projected_X = tm.filter(X, lens=lens)
Filtering by MDS.
...calculate distance matrix using the euclidean metric.
Finish filtering of points cloud data.
>>> clusterer = DBSCAN(eps=0.75, min_samples=1)
>>> cover = Cover(projected_data=MinMaxScaler().fit_transform(projected_X), resolution=20, overlap=0.75)
>>> graph = tm.map(data=StandardScaler().fit_transform(X), cover=cover, clusterer=clusterer)
Mapping on data (150, 4) using lens (150, 2)
...minimal number of points in hypercube to do clustering: 1
...create 296 nodes.
...calculate projection coordinates of nodes.
...construct a TDA graph.
...create 1394 edges.
Finish TDA mapping
>>> print(len(graph['nodes']),len(graph['edges']))
(296, 1394)
>>> print(graph['nodes'].items())

















Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Protected by WP Anti Spam