Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """ML LAB 2.1.ipynb
- Automatically generated by Colaboratory.
- Original file is located at
- https://colab.research.google.com/drive/13d-BD_VbSiSPyERDAWfMtxeAtNRLdhgn
- # ML EXP 2.1 -- SHRUTIKA PANDEY 102095004
- # LINEAR REGRESSION
- """
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
- dataset = pd.read_csv('sub.csv')
- x = dataset.iloc[:, :-1].values
- y = dataset.iloc[:, -1].values
- print(X)
- print(y)
- plt.plot(x,y)
- data.head()
- data.tail()
- from sklearn.model_selection import train_test_split
- X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 1/3, random_state = 0)
- from sklearn.linear_model import LinearRegression
- lr = LinearRegression()
- lr.fit(X_train, y_train)
- x_pred= lr.predict(X_train)
- y_pred = lr.predict(X_test)
- print(y_pred)
- #TRAINING DATA PLOT AND THE PREDCTED LINEAR
- plt.scatter(X_train, y_train, color = 'red')
- plt.plot(X_train, lr.predict(X_train), color = 'blue')
- plt.title('Lower living standard vs houses bought')
- plt.xlabel('Lower living standard of people')
- plt.ylabel('Prices of houses bought(in $1000)')
- plt.show()
- #TESTING DATA PLOT AND THE PREDCTED LINEAR
- plt.scatter(X_test, y_test, color = 'green')
- plt.plot(X_train, lr.predict(X_train), color = 'blue')
- plt.title('Lower living standard vs houses bought')
- plt.xlabel('Lower living standard of people')
- plt.ylabel('Prices of houses bought(in $1000)')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment