# Import necessary libraries
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
 
# Step 1: Create a dataset (sample data for house rentals)
data = {
    'Size (sq ft)': [850, 900, 1200, 1500, 1800, 2000, 2300, 2500, 2700, 3000],
    'Bedrooms': [2, 2, 3, 3, 4, 4, 5, 5, 5, 6],
    'Age (years)': [5, 10, 3, 20, 15, 10, 8, 12, 30, 20],
    'Location Score': [8, 7, 9, 6, 8, 8, 9, 9, 7, 6],
    'Rental Price (USD)': [1500, 1700, 2500, 3000, 3500, 3700, 4200, 4500, 4700, 5000]
}
 
df = pd.DataFrame(data)
 
# Step 2: Split the data into features (X) and target (y)
X = df[['Size (sq ft)', 'Bedrooms', 'Age (years)', 'Location Score']]
y = df['Rental Price (USD)']
 
# Step 3: Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
 
# Step 4: Train the Multiple Linear Regression model
model = LinearRegression()
model.fit(X_train, y_train)
 
# Step 5: Make predictions on the test set
y_pred = model.predict(X_test)
 
# Step 6: Evaluate the model
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
 
print("Model Evaluation:")
print(f"Mean Squared Error (MSE): {mse:.2f}")
print(f"R² Score: {r2:.2f}")