2 - Linear - Regression - Multivariate - Ipynb - Colaboratory
2 - Linear - Regression - Multivariate - Ipynb - Colaboratory
Variables
Below is the table containing home prices in monroe twp, NJ. Here price depends on area
(square feet), bed rooms and age of the home (in years). Given these prices we have to predict
prices of new homes based on area, bed rooms and age.
Given these home prices find out price of a home that has,
We will use regression with multiple variables here. Price can be calculated using following
equation,
Here area, bedrooms, age are called independant variables or features whereas price is a
dependant variable
import pandas as pd
import numpy as np
from sklearn import linear_model
df = pd.read_csv('homeprices.csv')
df
df.bedrooms.median()
4.0
df.bedrooms = df.bedrooms.fillna(df.bedrooms.median())
df
reg = linear_model.LinearRegression()
reg.fit(df.drop('price',axis='columns'),df.price)
normalize=False)
reg.coef_
reg.intercept_
221323.00186540408
Find price of home with 3000 sqr ft area, 3 bedrooms, 40 year old
reg.predict([[3000, 3, 40]])
array([498408.25158031])
112.06244194*3000 + 23388.88007794*3 + -3231.71790863*40 + 221323.00186540384
498408.25157402386
Find price of home with 2500 sqr ft area, 4 bedrooms, 5 year old
reg.predict([[2500, 4, 5]])
array([578876.03748933])
Exercise
In exercise folder (same level as this notebook on github) there is hiring.csv. This file contains
hiring statics for a firm such as experience of candidate, his written test score and personal
interview score. Based on these 3 factors, HR will decide the salary. Given this data, you need to
build a machine learning model for HR department that can help them decide salaries for future
candidates. Using this predict salaries for following candidates,
Answer