Practical Exercises Chapter 4
Exercise 1: Linear Regression
Task: You have the following dataset containing information about house prices. Use simple linear regression to predict the house price based on the size of the house.
Solution:
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
# Data: House size (X) and price (y)
X = np.array([800, 1000, 1200, 1500, 1800]).reshape(-1, 1)
y = np.array([150000, 180000, 210000, 250000, 300000])
# Initialize and train the linear regression model
model = LinearRegression()
# Predict for new house sizes ...