How to use 2D data

An introduction of using aleady dimension reduced data.

In this tutorial, we visualize iris dataset that was reduced 2d.

  • How to use 2d data.

Requirements

In [1]:
import numpy as np

from sklearn.datasets import load_iris

from renom_tda.topology import Topology
from renom_tda.lens import PCA

Dataset

Next, we have to load iris dataset. To accomplish this, we'll use the load_iris module included in the scikit-learn package.

The iris dataset consists of 150 data and data has 4 columns.

In [2]:
iris = load_iris()

data = iris.data
target = iris.target

Create test data

Next, we create test data.

In [3]:
topology = Topology()
topology.load_data(data)
metric = None
lens = [PCA(components=[0, 1])]
topology.fit_transform(metric=metric, lens=lens)
projected by PCA.
In [4]:
topology.point_cloud.shape
Out[4]:
(150, 2)
In [5]:
np.savetxt("test.csv", topology.point_cloud)

Import test data

In [6]:
data = np.loadtxt("test.csv")
In [7]:
data.shape
Out[7]:
(150, 2)
In [8]:
topology = Topology()
topology.load_data(data)

Create point cloud

Next, we create point cloud that is projected on 2 or 3 dimention space.

If you wan't to use aleady 2d data, you set parameters as follow.

In [9]:
topology.fit_transform(metric=None, lens=None)

Mapping to topological space

In [10]:
topology.map(resolution=15, overlap=0.5, eps=0.1, min_samples=3)
created 72 nodes.
created 201 edges.

Colorize & Show

In [11]:
topology.color(target, color_method="mode", normalize=True)
topology.show(fig_size=(10, 10), node_size=10, edge_width=2)
../../../_images/notebooks_tda_how-to-use-2d-data_notebook_18_0.png