1 and 2
# Import necessary libraries
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
# Load the dataset
# Replace ‘your_dataset.csv’ with the path to your file
# Ensure that your dataset has continuous numeric features and target variable
data = pd.read_csv(‘your_dataset.csv’)
# Define the features (X) and target (y) variables
# Replace ‘target_column’ with the name of your target variable
X = data.drop(columns=[‘target_column’])
y = data[‘target_column’]
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initialize the Linear Regression model
model = LinearRegression()
# Fit the model to the training data
model.fit(X_train, y_train)
# Predict on the test data
y_pred = model.predict(X_test)
# Calculate Mean Squared Error (MSE) and Root Mean Squared Error (RMSE)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
# Print the evaluation metrics
print(“Mean Squared Error (MSE):”, mse)
print(“Root Mean Squared Error (RMSE):”, rmse)