GithubHelp home page GithubHelp logo

arunraj2002 / correlationregression Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rameshkumar7777/correlationregression

0.0 0.0 0.0 19 KB

License: BSD 3-Clause "New" or "Revised" License

Jupyter Notebook 100.00%

correlationregression's Introduction

Correlation and Regression for Data Analysis

Aim :

To analyse given data using coeffificient of correlation and regression line. image

Software required :

Python

Theory:

Correlation describes the strength of an association between two variables, and is completely symmetrical, the correlation between A and B is the same as the correlation between B and A. However, if the two variables are related it means that when one changes by a certain amount the other changes on an average by a certain amount.

If y represents the dependent variable and x the independent variable, this relationship is described as the regression of y on x. The relationship can be represented by a simple equation called the regression equation. The regression equation representing how much y changes with any given change of x can be used to construct a regression line on a scatter diagram, and in the simplest case this is assumed to be a straight line.

Procedure :

image

Program

import math
import numpy as np
import matplotlib.pyplot as plt
x = [25,28,35,32,31,36,29,38,34,32]
y = [43,46,49,41,36,32,31,30,33,39]

sx=sy=sxy=sx2=sy2=0
for i in range(0,10):
    sx +=x[i]
    sy +=y[i]
    sxy+=x[i]*y[i]
    sx2+=x[i]**2
    sy2+=y[i]**2
    
n=10
r = (n*sxy-sx*sy)/(math.sqrt(n*sx2-sx*2)*math.sqrt(n*sy2-sy*2))
print("The Correlation Coefficient is %.3f"%r)
byx=(n*sxy-sx*sy)/(n*sx2-sx**2)
xmean=sx/n
ymean=sy/n
print("the reg line Y on x : 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,40,51)
y1=Reg(x)
plt.plot(x,y1,'r')
plt.xlabel("x-data")
plt.ylabel("y-label")
plt.legend(['REGRESSION LINE', 'DATA POINTS'])
plt.show()

Output :

o1

Results :

Thus the given data using coeffificient of correlation and regression line is implemented using python program.

correlationregression's People

Contributors

arunraj2002 avatar rameshkumar7777 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.