Advertisement
Guest User

Asa

a guest
Oct 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Wed Oct 26 11:11:36 2016
  5.  
  6. @author: Kamalkhan
  7. """
  8.  
  9. import numpy as np
  10. import csv
  11. import pandas as pd
  12. from sklearn import preprocessing
  13. from sklearn.cross_validation import train_test_split
  14. from sklearn.datasets import load_iris
  15. X = []
  16. Y = []
  17.  
  18. dataset = load_iris()
  19. iris = pd.DataFrame(dataset.data)
  20. iris.columns = ["s.L", "s.W", "p.L", "p.W"]
  21. iris_normalized = preprocessing.normalize(iris)
  22.  
  23. X = iris
  24. Y = dataset.target
  25.  
  26. X_norm = iris_normalized
  27.  
  28.  
  29. def scatter_plot():
  30. ind = 0
  31. x = np.arange(4)
  32. ys = [i+x+(i*x)**2 for i in range(4)]
  33. colors = cm.rainbow(np.linspace(0, 1, len(ys)))
  34. for i in range(4):
  35. for j in range(i+1,3):
  36. print 'Correlation between'+str(X.columns[i]) +' and '+str(X.columns[j])
  37. print 'Correlation: '+ str((pearsonr(np.array(X)[:,j], np.array(X)[:,i])[0]))
  38. for feature,target in zip(np.array(X)[:,j], np.array(X)[:,i]):
  39. plt.scatter(feature,target,color=colors[ind])
  40. ind+=1
  41. plt.legend()
  42. plt.show()
  43.  
  44.  
  45.  
  46. def norm_scatter_plot():
  47. ind = 0
  48. x = np.arange(4)
  49. ys = [i+x+(i*x)**2 for i in range(4)]
  50. colors = cm.rainbow(np.linspace(0, 1, len(ys)))
  51. for i in range(4):
  52. for j in range(i+1,3):
  53. print 'Correlation between'+str(X.columns[i]) +' and '+str(X.columns[j])
  54. print 'Correlation: '+ str((pearsonr(np.array(X)[:,j], np.array(X)[:,i])[0]))
  55. for feature,target in zip(np.array(X_norm)[:,j], np.array(X_norm)[:,i]):
  56. plt.scatter(feature,target,color=colors[ind])
  57. ind+=1
  58. plt.legend()
  59. plt.show()
  60.  
  61.  
  62. print 'After normalization-->'
  63. scatter_plot()
  64.  
  65. print 'Before normalization-->'
  66. norm_scatter_plot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement