In [1]:
import sys
sys.path.append('../scripts/pycogent/')
In [11]:
import approximate_mds
In [41]:
from scipy.cluster import hierarchy
from scipy.spatial import distance
from scipy.spatial.distance import squareform,pdist
In [14]:
from sklearn import datasets
data = datasets.load_digits()
X = data.data
Y = data.target
In [33]:
c = hierarchy.linkage(X,'single')
d = distance.squareform(hierarchy.cophenet(c))
In [43]:
euc_d = squareform(pdist(X))
G = nx.Graph(d)
G_ = nx.minimum_spanning_tree(G)
In [44]:
def dist(i,j):
return nx.shortest_path_length(G,i,j)
In [53]:
approximate_mds.
approximate_mds.nystrom()
Out[53]:
In [39]:
import networkx as nx
In [ ]:
nx.
In [ ]:
In [34]:
X_ = approximate_mds.cmds_tzeng(d,dim=2)[0]
In [35]:
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)
Out[35]:
In [36]:
from sklearn.manifold import MDS
mds = MDS(dissimilarity='precomputed')
X_ = mds.fit_transform(d)
In [37]:
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)
Out[37]:
In [ ]: