Advertisement
Guest User

Untitled

a guest
May 6th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #coding:utf-8
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. def scale(X):
  6. """データ行列Xを属性ごとに標準化したデータを返す"""
  7. # 属性の数(=列の数)
  8. col = X.shape[1]
  9.  
  10. # 属性ごとに平均値と標準偏差を計算
  11. mu = np.mean(X, axis=0)
  12. sigma = np.std(X, axis=0)
  13.  
  14. # 属性ごとデータを標準化
  15. for i in range(col):
  16. X[:,i] = (X[:,i] - mu[i]) / sigma[i]
  17.  
  18. return X
  19.  
  20. # faithful.txtデータをロード
  21. data = np.genfromtxt("faithful.txt")
  22. X_train = scale(data)
  23. N = len(X_train)
  24.  
  25. # 散布図をプロット
  26. plt.plot(X_train[:, 0], X_train[:, 1], 'gx')
  27. plt.xlim(-2.5, 2.5)
  28. plt.ylim(-2.5, 2.5)
  29. plt.grid()
  30. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement