140k views
3 votes
Using the estimated regression model, what median house price is predicted for a tract in the Boston area that does not bound the Charles River, has a crime rate of 0.1, and where the average number of rooms per house is 6?

1 Answer

4 votes

Answer:

The predicted median house price "medv" is $20,775.

Step-by-step explanation:

The python code below uses the python's scikit-learn package to program the housing model using multiple factor linear regression.

import pandas as pd

from sklearn.linear_model import LinearRegression

from sklearn.model_selection import train_test_split

df = pd.read_csv('Boston.csv')

df.head(10)

y = df[['medv']]

x = df[['crim', 'chas', 'rm']]

x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.75, test_size=0.25, random_state=0)

regr = LinearRegression()

regr.fit(x_train, y_train)

print(regr.coef_)

result = (regr.predict([[0.1,0,6]])).tolist()

print(f"The mean price of house in boston with 6 rooms: {round(result[0][0], 2)}")

User Kaydene
by
5.5k points