Guest User

Untitled

a guest
Dec 15th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. # In[1]:
  4.  
  5.  
  6. from numpy import *
  7. import operator
  8. from os import listdir
  9. import matplotlib
  10. import matplotlib.pyplot as plt
  11. import pandas as pd
  12. from numpy.linalg import *
  13. from scipy.stats.stats import pearsonr
  14. from numpy import linalg as la
  15.  
  16.  
  17. # In[2]:
  18.  
  19.  
  20. # load data points
  21. raw_data = pd.read_csv("C:/Users/Sony/Documents/Iris dataset.csv",delimiter=',',skiprows=1)
  22.  
  23.  
  24. # In[3]:
  25.  
  26.  
  27. raw_data
  28.  
  29.  
  30. # In[4]:
  31.  
  32.  
  33. samples,features = shape(raw_data)
  34.  
  35.  
  36. # In[7]:
  37.  
  38.  
  39. def svd(raw_data, S=2):
  40.  
  41. #calculate SVD
  42. U, s, V = linalg.svd( raw_data )
  43. Sig = mat(eye(S)*s[:S])
  44. #tak out columns you don't need
  45. newdata = U[:,:S]
  46.  
  47. # this line is used to retrieve dataset
  48. #~ new = U[:,:2]*Sig*V[:2,:]
  49.  
  50. fig = plt.figure()
  51. ax = fig.add_subplot(1,1,1)
  52. colors = ['blue','red','black']
  53. for i in xrange(samples):
  54. ax.scatter(newdata[i,0],newdata[i,1], color= colors[int(raw_data[i,-1])])
  55.  
  56.  
  57. # In[8]:
  58.  
  59.  
  60. plt.xlabel('SVD1')
  61. plt.ylabel('SVD2')
  62.  
  63.  
  64. # In[9]:
  65.  
  66.  
  67. plt.show()
Add Comment
Please, Sign In to add comment