0% found this document useful (0 votes)
14 views2 pages

Linear Regression - Py

The document outlines a process for performing linear regression analysis on a house price dataset using Python in Google Colab. It includes steps for data preparation, model training, and evaluation metrics such as Mean Squared Error (MSE) and R squared value. Additionally, it provides a visualization of the dataset and predictions for house prices based on size.

Uploaded by

Daniyal Shahbaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Linear Regression - Py

The document outlines a process for performing linear regression analysis on a house price dataset using Python in Google Colab. It includes steps for data preparation, model training, and evaluation metrics such as Mean Squared Error (MSE) and R squared value. Additionally, it provides a visualization of the dataset and predictions for house prices based on size.

Uploaded by

Daniyal Shahbaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

#Step1.

Remove blank row and columns


#Step2. File save as CSV
#Step3. Upload it on colab file upload
#Step4. Run the command
import os
print([Link]()) # Lists all files in current directory
import os
print([Link]()) # Prints current working directory
import pandas as pd
import numpy as np
import [Link] as plt
from sklearn.linear_model import LinearRegression
from [Link] import mean_squared_error
import math
from [Link] import files
uploaded = [Link]() # Use the UI to select your file
dataset = pd.read_csv('Dataset_House_Price.csv')

#read .csv into a DataFrame


#dataset = pd.read_csv('C:\\Users\\User\\Desktop\\house_prices.csv')
dataset = pd.read_csv('Dataset_House_Price.csv')
size=dataset['sqft_living']
price=dataset['price']

#machine learing handle arrays not dataframes


x = [Link](size).reshape(-1,1)
y = [Link](price).reshape(-1,1)

#we use Linear Regression + fit() is the training


model = LinearRegression()
[Link](x, y)

#MSE and R value


regression_model_mse = mean_squared_error(x, y)
print("MSE: ", [Link](regression_model_mse))
print("R squared value:", [Link](x,y))

#we can get the b values after the model fit


#this is the b0
print(model.coef_[0])
#this is b1 in our model
print(model.intercept_[0])

#visualize the dataset with the fitted model


[Link](x, y, color= 'green')
[Link](x, [Link](x), color = 'black')
[Link] ("Linear Regression")
[Link]("Size")
[Link]("Price")
[Link]()

#Predicting the prices


print("Prediction by the model:" , [Link]([[2000]]))

You might also like