In: Computer Science
Can you please solve these questions/ statements using python? I started with "importing" the file. I only need question one to be answered not two-four. Can use whatever data frame of choice, I just need a sample code for each line. Thank you
#1. #Fit a linear regression model on data: USA_housing.csv to
predict the Price of the house.
import pandas as pd
housing_df = pd.read_csv("USA_Housing.csv")
#Income: Avg. area income
#Age: Avg age of the houses
#Bedrooms: Avg No of bedrooms
#Rooms: Avg No of rooms
#Population: Population of the area
#Price: Average price in the area
#Address: THink of them as different ZIPcodes
#Also try to see if the model performance can be improved with feature selection.
#2. What is the difference between correlation and regression.
#3. Give three situations when there is correlation as well as causation
#4. Give three situations when there is correlation but no causation
Code
import pandas as pd
from sklearn.linear_model import LinearRegression
#loading the dataset
housing_df = pd.read_csv('USA_Housing.csv')
#dropping the address feature as it not not important in building the model
housing_df = housing_df.drop(['Address'], axis=1)
#seprating input feature and output features
x = housing_df.drop(['Price'], axis=1)
y = housing_df['Price']
#training the model
reg = LinearRegression()
reg.fit(x,y)
#predicting the value
predicted_values = reg.predict(x)
print(predicted_values)
Code Screenshot
Comments have been provided in the code and as well as screenshot of the code is also attached for the reference.
Please execute the code in any Python IDE to see the output.