P 6 Regression and its types

 

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

data = pd.read_csv("C:\\Users\\Downloads\\DS\\HousingPrice.csv")


X = data[["GDP"]]
y = data["HPI"]  

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = LinearRegression()
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

mse = mean_squared_error(y_test, y_pred)
print("Mean Squared Error:", mse)

print("Intercept:", model.intercept_)
print("Coefficient:", model.coef_)
print("R-squared:", model.score(X_test, y_test))

X = data[["GDP", "CPI", "FED", "Income Distribution", "ECI", "Housing Inventory Estimate", "Rental Vacancy Rate", "Population Level", "CPI"]]  # feature variables

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = LinearRegression()
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

mse = mean_squared_error(y_test, y_pred)
print("Mean Squared Error (Multiple Regression):", mse)
print("R-squared (Multiple Regression):", model.score(X_test, y_test))