Question: kindly help check this code data file is task1.csv def gen_pearson(data): data= ['task1.csv'] col_names = data [0] #create list of tuples of pairs of columns

kindly help check this code data file is task1.csv

def gen_pearson(data): data= ['task1.csv'] col_names = data [0] #create list of tuples of pairs of columns col_pairs = [(col_names[i], col_names[j]) for i in range(len(col_names)) for j in range (i+1, len(col_names))] #calculate pearson correlation coefficient for each pair columns coefficients = [] for pair in col_pairs: col_1 = [row[pair[0]] for row in data[1:]] col_2 = [row[pair[1]] for row in data[1:]]

coefficient = sum((a - mean_col_1) * (b - mean_col_2) for (a,b) in zip (col_1, col_2)) / len (col_1) stdev_x = (sum((a - mean_col_1) **2 for a in col_1)/len(col_1)) **0.5 stdev_y = (sum((b - mean_col_2) **2 for b in col_2)/len(col_2)) **0.5 pearson_result = cov/(stdev_x * stdev_y) print(pearson_result)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!