CJamie

linear

Mar 23rd, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """ML LAB 2.1.ipynb
  3.  
  4. Automatically generated by Colaboratory.
  5.  
  6. Original file is located at
  7. https://colab.research.google.com/drive/13d-BD_VbSiSPyERDAWfMtxeAtNRLdhgn
  8.  
  9. # ML EXP 2.1 -- SHRUTIKA PANDEY 102095004
  10.  
  11. # LINEAR REGRESSION
  12. """
  13.  
  14. import numpy as np
  15. import matplotlib.pyplot as plt
  16. import pandas as pd
  17.  
  18. dataset = pd.read_csv('sub.csv')
  19. x = dataset.iloc[:, :-1].values
  20. y = dataset.iloc[:, -1].values
  21. print(X)
  22. print(y)
  23. plt.plot(x,y)
  24.  
  25. data.head()
  26.  
  27. data.tail()
  28.  
  29. from sklearn.model_selection import train_test_split
  30. X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 1/3, random_state = 0)
  31.  
  32. from sklearn.linear_model import LinearRegression
  33. lr = LinearRegression()
  34. lr.fit(X_train, y_train)
  35.  
  36. x_pred= lr.predict(X_train)
  37. y_pred = lr.predict(X_test)
  38. print(y_pred)
  39.  
  40. #TRAINING DATA PLOT AND THE PREDCTED LINEAR
  41. plt.scatter(X_train, y_train, color = 'red')
  42. plt.plot(X_train, lr.predict(X_train), color = 'blue')
  43. plt.title('Lower living standard vs houses bought')
  44. plt.xlabel('Lower living standard of people')
  45. plt.ylabel('Prices of houses bought(in $1000)')
  46. plt.show()
  47.  
  48. #TESTING DATA PLOT AND THE PREDCTED LINEAR
  49. plt.scatter(X_test, y_test, color = 'green')
  50. plt.plot(X_train, lr.predict(X_train), color = 'blue')
  51. plt.title('Lower living standard vs houses bought')
  52. plt.xlabel('Lower living standard of people')
  53. plt.ylabel('Prices of houses bought(in $1000)')
  54. plt.show()
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment