From 2f4b5de75c8ef6d3ab7f7b73d776106925bc56bb Mon Sep 17 00:00:00 2001 From: Nivedhakaliaperumal76 Date: Tue, 26 May 2026 14:02:09 +0530 Subject: [PATCH] Update README.md --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 85c90cdc..e8484162 100644 --- a/README.md +++ b/README.md @@ -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 +image + +# Result +Thus to analyse given data using coeffificient of correlation and regression line is created.