Advertisement
coffeebeforecode

linearRegression.py

Feb 24th, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.linear_model import LinearRegression
  4.  
  5. #X = np.array(([1, 1], [1, 2], [2, 2], [2,3]))
  6. #y = np.array(([ 6, 8, 9, 11]))
  7.  
  8. rows = int(input("Input number of rows: "))
  9. cols = int(input("Input number of features (not including label): "))
  10.  
  11. print("input table (with y)")
  12. X = list()
  13. y = list()
  14. for i in range(rows):
  15. inp = list(map(int, input().split()))
  16. X.append(inp[:-1])
  17. y.append(inp[-1])
  18.  
  19. X = np.array(tuple(X))
  20. y = np.array((y))
  21. #print(tuple([y]))
  22.  
  23. reg = LinearRegression().fit(X, y)
  24.  
  25. print("score", reg.score(X, y))
  26. print("intercept", reg.intercept_)
  27. print("coeff", reg.coef_)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement