sk5_datasets.py 803 B

1234567891011121314151617181920212223242526272829303132
  1. # View more python learning tutorial on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. """
  5. Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
  6. """
  7. from __future__ import print_function
  8. from sklearn import datasets
  9. from sklearn.linear_model import LinearRegression
  10. import matplotlib.pyplot as plt
  11. loaded_data = datasets.load_boston()
  12. data_X = loaded_data.data
  13. data_y = loaded_data.target
  14. model = LinearRegression()
  15. model.fit(data_X, data_y)
  16. print(model.predict(data_X[:4, :]))
  17. print(data_y[:4])
  18. X, y = datasets.make_regression(n_samples=100, n_features=1, n_targets=1, noise=10)
  19. plt.scatter(X, y)
  20. plt.show()