fork download
  1. import numpy as np
  2. from sklearn.linear_model import LinearRegression
  3.  
  4. x=np.array([[1],[2],[3],[4],[5]])
  5. y=np.array([2,4,5,7,8])
  6.  
  7. model=LinearRegression()
  8. model.fit(x,y)
  9.  
  10. x_test=np.array([[6],[7],[8]])
  11. y_pred=model.predict(x_test)
  12.  
  13. print("Coefficient",model.coef_)
  14. print("Intercept",model.intercept_)
  15. print("Predict",y_pred)
Success #stdin #stdout 0.33s 64612KB
stdin
Standard input is empty
stdout
('Coefficient', array([1.5]))
('Intercept', 0.7000000000000011)
('Predict', array([ 9.7, 11.2, 12.7]))