Lab6 Hoursing Price Regression
Lab6 Hoursing Price Regression
Lab 6: Regression
Subject: ADY201 Author: Hieu Nguyen
Problem Statement
Suppose you are working with a housing prices dataset. The dataset includes the following
information:
hoursing_price.csv
import numpy as np
import pandas as pd
# Create a DataFrame
df = pd.DataFrame({'size': size, 'bedrooms': bedrooms, 'price': price})
import statsmodels.api as sm
1
ADY201 Hieu Nguyen
• Constant (Intercept): The predicted price of a house when the size and number of
bedrooms are zero.
• Coefficients (size, bedrooms): The change in the house price for a one-unit change in
size or the number of bedrooms, holding other variables constant.
• R-squared: A measure of how well the independent variables explain the variability of
the dependent variable.
• P-values: Indicate whether the coefficients are statistically significant.
Use the matplotlib library to visualize the relationship between the variables and the regression
line.
plt.subplot(1, 2, 1)
plt.scatter(df['size'], df['price'], label='Data')
plt.plot(df['size'], model.predict(X), color='red', label='Regression
Line')
plt.xlabel('Size (square meters)')
plt.ylabel('Price (thousand dollars)')
plt.title('Price vs Size')
plt.legend()
plt.tight_layout()
plt.show()