Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,64 @@ If y represents the dependent variable and x the independent variable, this rela
![image](https://user-images.githubusercontent.com/104613195/168225866-ac8f6610-bdc3-4ac2-a24e-2b24ba08e189.png)

# Program :
NAME: K NIVEDHA

![image](https://github.com/ramjan1729/Correlation_Regression/assets/103921593/9eb48cbf-8ca3-4cd9-8440-ff45fd98333e)
REF NO: 212225230204

```import numpy as np
import math
import matplotlib.pyplot as plt

# Result
x=[ int(i) for i in input().split()]
y=[ int(i) for i in input().split()]

N=len(x)

Sx=0
Sy=0
Sxy=0
Sx2=0
Sy2=0

for i in range(0,N):
Sx=Sx+x[i]
Sy=Sy+y[i]
Sxy=Sxy+x[i]*y[i]
Sx2=Sx2+x[i]**2
Sy2=Sy2+y[i]**2

r=(N*Sxy-Sx*Sy)/(math.sqrt(N*Sx2-Sx**2)*math.sqrt(N*Sy2-Sy**2))

print("The Correlation coefficient is %0.3f"%r)

byx=(N*Sxy-Sx*Sy)/(N*Sx2-Sx**2)

xmean=Sx/N
ymean=Sy/N

print("The Regression line Y on X is ::: y = %0.3f + %0.3f (x-%0.3f)"%(ymean,byx,xmean))

plt.scatter(x,y)

# Output
def Reg(x):
return ymean + byx*(x-xmean)

x=np.linspace(20,80,51)

y1=Reg(x)

plt.plot(x,y1,'r')

plt.xlabel('x-data')
plt.ylabel('y-data')

plt.legend(['Regression Line','Data points'])

plt.show()
```

# Output
<img width="835" height="637" alt="image" src="https://github.com/user-attachments/assets/c222ba61-cd51-441c-b68d-7dc443df0801" />

# Result
Thus to analyse given data using coeffificient of correlation and regression line is created.