Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import numpy as np
  2. from sklearn.datasets import load_boston
  3. from sklearn.model_selection import train_test_split
  4.  
  5. def standardize(x):
  6. mean_x = x.mean(axis=0)
  7. std_x = x.std(axis=0)
  8. return (x - mean_x)/std_x
  9.  
  10. boston = load_boston()
  11. X = boston.data
  12. y = boston.target
  13. X_std = standardize(X)
  14. x_0 = np.ones(X.shape[0]).reshape(-1, 1)
  15. X_std = np.hstack([x_0, X_std])
  16. y_std = standardize(y)
  17. X_train, X_test, y_train, y_test = train_test_split(X_std, y_std, test_size=0.3, random_state=42)
  18. print(X_train.shape)
  19. print(X_test.shape)
  20. print(y_train.shape)
  21. print(y_test.shape)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement