We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Artificial Intelligence
- Statistics and Machine Learning
- Correlation and Regression Lines - A Quick Recap #1
- Discussions
Correlation and Regression Lines - A Quick Recap #1
Correlation and Regression Lines - A Quick Recap #1
Sort by
recency
|
108 Discussions
|
Please Login in order to post a comment
this is why leetcode is a million times better
I cant believe companies pay for this! For those who get an error while submitting, just run the print statement with your answer. There are no hidden testcases, it's just looking for the correlation value with 3 decimal places.
Your code is good, better than this site imho
I'm very confused about the input data type of "STDIN", the input is 2 list or numpy, So is STDIN a tuple ???
New to HackerRank and question seems to be way more unclear compared Leetcode
HERE'S MY CODE def mean(x): '''calculating mean of the list''' n = len(x) sum_x = sum(x) return sum_x/n
defining x square
def squared_num(x): '''squaring each item in the list and redefine a new list''' lst = [] for i in x: lst.append(i**2) return lst
def mul_of_xy(x,y): '''multiplying corresponding items of each list''' gst = [] for i in range(len(x)): gst.append(x[i] * y[i]) return gst
def karl_pearson_corr(x,y): n= len(x) mean_x = mean(x) mean_y = mean(y) var_x = (((1/n)*sum(squared_num(x)))-(mean_x**2)) var_y = (((1/n)*sum(squared_num(y)))-(mean_y**2)) cov_xy = ((1/n)*sum(mul_of_xy(x,y)))-(mean_x * mean_y) num = cov_xy den = (var_x * var_y)**(1/2) r_xy = num/den return r_xy
x = [15,12,8,8,7,7,7,6,5,3] y = [10,25,17,11,13,17,20,13,9,15]
print(karl_pearson_corr(x,y))
what format is the input? I am assuming it is a string and splitting by newline to break the input into physics and history but this is not passing the test cases