From 99760eb0cd8a005924147c29f470c2caace76c23 Mon Sep 17 00:00:00 2001 From: Dhayananth-P-S Date: Mon, 11 Nov 2024 13:17:49 +0530 Subject: [PATCH] Update README.md --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 85c90cdc..f1019aa8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Correlation and regression for data analysis +# EX:03 Correlation and regression for data analysis # Aim : To analyse given data using coeffificient of correlation and regression line @@ -20,10 +20,47 @@ 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 : +```PY +Name : DHAYANANTH P S +Register Number : 212223040039 +import numpy as np +import math +import matplotlib.pyplot as plt +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) +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']) +``` ![image](https://github.com/ramjan1729/Correlation_Regression/assets/103921593/9eb48cbf-8ca3-4cd9-8440-ff45fd98333e) # Result +![image](https://github.com/user-attachments/assets/c355755a-3f44-43eb-b17b-29bd4e3dc92e) # Output