File size: 453 Bytes
3aaaba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pandas as pd
from sklearn.linear_model import LinearRegression

# Sample data
data = {
    "size": [800, 1000, 1200, 1500, 1800],
    "bedrooms": [1, 2, 2, 3, 3],
    "price": [120000, 150000, 170000, 220000, 260000]
}

df = pd.DataFrame(data)

X = df[["size", "bedrooms"]]
y = df["price"]

model = LinearRegression()
model.fit(X, y)

# Predict a new house
prediction = model.predict([[1400, 3]])
print(f"Predicted price: ${prediction[0]:,.0f}")