Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions