Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- # In[1]:
- from numpy import *
- import operator
- from os import listdir
- import matplotlib
- import matplotlib.pyplot as plt
- import pandas as pd
- from numpy.linalg import *
- from scipy.stats.stats import pearsonr
- from numpy import linalg as la
- # In[2]:
- # load data points
- raw_data = pd.read_csv("C:/Users/Sony/Documents/Iris dataset.csv",delimiter=',',skiprows=1)
- # In[3]:
- raw_data
- # In[4]:
- samples,features = shape(raw_data)
- # In[7]:
- def svd(raw_data, S=2):
- #calculate SVD
- U, s, V = linalg.svd( raw_data )
- Sig = mat(eye(S)*s[:S])
- #tak out columns you don't need
- newdata = U[:,:S]
- # this line is used to retrieve dataset
- #~ new = U[:,:2]*Sig*V[:2,:]
- fig = plt.figure()
- ax = fig.add_subplot(1,1,1)
- colors = ['blue','red','black']
- for i in xrange(samples):
- ax.scatter(newdata[i,0],newdata[i,1], color= colors[int(raw_data[i,-1])])
- # In[8]:
- plt.xlabel('SVD1')
- plt.ylabel('SVD2')
- # In[9]:
- plt.show()
Add Comment
Please, Sign In to add comment