-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correlation and Regression Lines - A Quick Recap#1
Hackerrank Solution
- Loading branch information
1 parent
f8312bf
commit f8648aa
Showing
1 changed file
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
|
||
#RAMESH CHANDRA | ||
|
||
import math | ||
x = [15 , 12 , 8 , 8 , 7 , 7 , 7 , 6 , 5 , 3] | ||
y = [10 ,25 , 17 ,11 , 13 , 17 , 20 , 13 , 9 , 15] | ||
#calculate mean of x and y | ||
sum_x,sum_y=0,0 | ||
for i in xrange(len(x)): | ||
sum_x,sum_y=sum_x+x[i],sum_y+y[i] | ||
|
||
mean_x = float(sum_x)/len(x) | ||
mean_y = float(sum_y)/len(y) | ||
A, B , C = 0,0,0; | ||
#now calculate r = A/sqrt(B*C) | ||
# A = sum ((x[i]-x_mean_x)*(y[i]-mean_y)) | ||
# B = sum(x[i]-mean_x)^2 | ||
# C = sum(y[i]-mean_y)^2 | ||
|
||
A, B , C ,= 0,0,0; | ||
for i in xrange(len(x)): | ||
A += (x[i]-mean_x)*(y[i]-mean_y) | ||
B += (x[i]-mean_x)**2 | ||
C += (y[i]-mean_y)**2 | ||
#Co-relation Coefficient | ||
ans = float(A)/math.sqrt(B*C) | ||
print ans | ||
#for more info....go to this link https://www.youtube.com/watch?v=2SCg8Kuh0tE |