Spaces:
Sleeping
Sleeping
File size: 525 Bytes
b12e4cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Assignment 4: Linear Regression on Synthetic Data
# Build a linear regression model to predict house prices
import numpy as np
from sklearn.linear_model import LinearRegression
# Synthetic dataset
X = np.array([[1, 2], [2, 4], [3, 6], [4, 8]]) # Features: size, rooms
y = np.array([100, 200, 300, 400]) # Prices
# Train model
model = LinearRegression()
model.fit(X, y)
# Predict on new data
new_data = np.array([5, 10]) # Error: Shape mismatch, should be [[5, 10]]
print(f"Predicted price: {model.predict(new_data)}") |