Mercurial > repos > bgruening > ctb_machine_learning
comparison mds_plot.py @ 0:fe542273784f draft default tip
Uploaded
| author | bgruening |
|---|---|
| date | Thu, 15 Aug 2013 03:39:14 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fe542273784f |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import argparse | |
| 4 import os | |
| 5 import sklearn.manifold | |
| 6 import numpy | |
| 7 import math | |
| 8 import pylab | |
| 9 | |
| 10 if __name__ == "__main__": | |
| 11 parser = argparse.ArgumentParser( | |
| 12 description="""2D multidimenisnal scaling of NxN matrices with scatter plot""" | |
| 13 ) | |
| 14 | |
| 15 parser.add_argument("-i", "--input", dest="sm", | |
| 16 required=True, | |
| 17 help="Path to the input file.") | |
| 18 parser.add_argument("--oformat", default='png', help="Output format (png, svg)") | |
| 19 parser.add_argument("-o", "--output", dest="output_path", | |
| 20 help="Path to the output file.") | |
| 21 | |
| 22 args = parser.parse_args() | |
| 23 mds = sklearn.manifold.MDS( n_components=2, max_iter=300, eps=1e-6, dissimilarity='precomputed' ) | |
| 24 data = numpy.fromfile( args.sm ) | |
| 25 d = math.sqrt( len(data) ) | |
| 26 sm = numpy.reshape( data, ( d,d )) | |
| 27 pos = mds.fit( sm ).embedding_ | |
| 28 pylab.scatter( pos[:,0],pos[:,1] ) | |
| 29 pylab.savefig( args.output_path, format=args.oformat ) |
