Python for Data Science: Laboratory Programs in Python: Descriptive Analytics: Generation of correlation coefficient
Correlation Coefficient for Quantitative Data
• The strength of correlation is measured by correlation coefficient.
• The range of correlation coefficient is from ‒1 to 1.
• If a correlation coefficient has a value zero then that means there is no correlation.
• If the correlation coefficient has exactly ‒1 value then it is called perfect negative correlation.
• If the correlation coefficient has exactly 1 value then it is called perfect positive correlation.
• There are various types of correlation coefficients. Out of which, Pearson Product Moment Correlation is most popularly used type of method used for obtaining correlation coefficient.
• The correlation coefficient is denoted by variable r.

r = [ n(Σxy) – (Σx) (Σy) ] / √[n Σx2 ‒ (Ex)2] [n Σy2 ‒ (Σy)2]
where
n = Quantity of information
Σx = Total of the first variable value
Σy = Total of the second variable value
Σxy = Sum of the product of first and second value
Σx2 = Sum of the squares of the first value
Σy2 = Sum of the squares of the second value
For example ‒ Following are the values of x and y. We will find the correlation coefficient

We will obtain x2, y2 and xy values.

Here n is total no. of data items, it is 12.
Σx = Sum of x = 149
Σy = Sum of y = 214
Σx2 = 1909
Σy2 = 3876
Σxy = 2716
Now we will put these values in the formula –
r = [ n(Σxy) – (Σx) (Σy) ] / √[n Σx2 ‒ (Ex)2] [n Σy2 ‒ (Σy)2]

r = (12) (2716) — (149) (214) / √[(12) (1909) − (149)2] [(12) (3876) – (214)2]
r = 0.62
Thus correlation coefficient is nearer to + 1. Hence it is strong positive correlation.
• Pearson's correlation coefficient (r) measures the strength and direction of a relationship between two variables.
■ If r = 1, perfect positive correlation.
■ Ifr= ‒1, perfect negative correlation.
■ If r = 0, no correlation.
• If we repeatedly take samples from a population and calculate r each time, we get a sampling distribution of r.
• This is the distribution of Pearson's correlation coefficients (r) calculated from repeated samples of the same size taken from a population.
• This distribution helps us determine if an observed correlation is statistically significant.
• For example ‒ Consider that there are 1000 students (population) whose math and science scores are noted. There are 30 students in each sample. Randomly 100 such samples are recorded. Then calculate correlation coefficient (r) between maths and science scores for each sample. When we plot these 100 correlation coefficients on a graph then we get the sampling distribution of r. The distribution of r is approximately normal.
• Correlation shows how two quantitative variables move together.
• A scatter plot gives a visual idea of the relationship, while the correlation coefficient (r) measures its strength and direction numerically.
• For quantitative data, Pearson's formula is used to computer.
Python for Data Science: Laboratory Programs in Python : Tag: Computer Programming, Python, Data Science : Laboratory Programs in Python - Generation of correlation coefficient
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Python for Data Science
AD25201 2nd Semester AIDS Dept, 4th Semester CSE, CSE(CY) Departments | 2025 Regulation | 2nd, 4th Semester 2025 Regulation
Python for Data Science - Laboratory
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Foundations of Data Science using Python
IT25201 2nd Semester IT Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 1st, 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation