sk6_model_attribute_method.py 772 B

123456789101112131415161718192021222324
  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. loaded_data = datasets.load_boston()
  11. data_X = loaded_data.data
  12. data_y = loaded_data.target
  13. model = LinearRegression()
  14. model.fit(data_X, data_y)
  15. print(model.predict(data_X[:4, :]))
  16. print(model.coef_)
  17. print(model.intercept_)
  18. print(model.get_params())
  19. print(model.score(data_X, data_y)) # R^2 coefficient of determination