SNT 7
SNT 7
Regression analysis is widely used in industries such as retail, meteorology, and real
estate to predict future trends. In this assignment, you will:
Submit following
Data Preprocessing
CSPIT-IT 1
MA262-SNT D24IT179
CSPIT-IT 2
MA262-SNT D24IT179
CSPIT-IT 3
MA262-SNT D24IT179
Code : -
# 📌 Import necessary libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
%matplotlib inline # Ensures plots are displayed in Jupyter Notebook
CSPIT-IT 4
MA262-SNT D24IT179
plt.show()
# 🔹 Correlation Heatmap
plt.figure(figsize=(8,6))
sns.heatmap(df.corr(), annot=True, cmap='coolwarm', fmt=".2f")
plt.title("Correlation Heatmap of Variables")
plt.show()
CSPIT-IT 5
MA262-SNT D24IT179
plt.figure(figsize=(6,4))
sns.scatterplot(x=y_pred, y=residuals, color='purple')
plt.axhline(y=0, color='red', linestyle='--')
plt.title("Residuals vs Predicted Values")
plt.xlabel("Predicted Values")
plt.ylabel("Residuals")
plt.show()
# 📌 Interpretation of Results
interpretation = """
🔹 **Interpretation of Coefficients:**
- `RM (Rooms)` → **Positive Coefficient**: More rooms increase house prices.
- `LSTAT (Lower Status %)` → **Negative Coefficient**: Higher % of lower-status people
reduces house prices.
- `PTRATIO (Pupil-Teacher Ratio)` → **Negative Coefficient**: Higher class sizes
negatively affect house prices.
🔹 **Limitations:**
1. The model assumes **linear relationships**, but real estate pricing may have non-
linear effects.
2. It does not account for **location**, crime rates, or neighborhood factors.
3. The dataset may contain **outliers** affecting predictions.
"""
CSPIT-IT 6
MA262-SNT D24IT179
Output : -
CSPIT-IT 7
MA262-SNT D24IT179
CSPIT-IT 8
MA262-SNT D24IT179
CSPIT-IT 9
MA262-SNT D24IT179
CSPIT-IT 10
MA262-SNT D24IT179
CSPIT-IT 11
MA262-SNT D24IT179
CSPIT-IT 12
MA262-SNT D24IT179
- `LSTAT (Lower Status %)` → **Negative Coefficient**: Higher % of lower-status people reduces
house prices.
- `PTRATIO (Pupil-Teacher Ratio)` → **Negative Coefficient**: Higher class sizes negatively affect
house prices.
🔹 **Limitations:**
1. The model assumes **linear relationships**, but real estate pricing may have non-linear effects.
CSPIT-IT 13