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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started