-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_2_Linear_Regression.py
52 lines (40 loc) · 1.1 KB
/
exp_2_Linear_Regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""exp-2.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1GDApzNTfBgy2LwvPuovcZyiN7rSf8Ysg
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_csv("AirQuality.csv",sep=',')
df
sns.pairplot(df)
plt.show()
a=df.head(100)
plt.scatter(a['NO2(GT)'], a['NOx(GT)'])
plt.title('NO2 vs NOx')
plt.xlabel('NO2')
plt.ylabel('NOx')
plt.show()
X = a['NO2(GT)']
y = a['NOx(GT)']
mean_X = np.mean(X)
mean_y = np.mean(y)
numerator = np.sum((X - mean_X) * (y - mean_y))
denominator = np.sum((X - mean_X)**2)
slope = numerator / denominator
intercept = mean_y - slope * mean_X
y_pred = slope * X + intercept
mse = np.mean((y - y_pred)**2)
r2 = 1 - (np.sum((y - y_pred)**2) / np.sum((y - mean_y)**2))
print(f'Mean Squared Error: {mse}')
print(f'R-squared: {r2}')
plt.scatter(X, y, label='Actual Data')
plt.plot(X, y_pred, color='red', linewidth=2, label='Regression Line')
plt.title('Wine pH vs Quality with Regression Line')
plt.xlabel('NO2')
plt.ylabel('NOx')
plt.legend()
plt.show()