0
0
ML Pythonprogramming~10 mins

Correlation analysis in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the Pearson correlation coefficient between two lists.

ML Python
import numpy as np
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
correlation = np.[1](x, y)
print(correlation)
Drag options to blanks, or click blank then click option'
Acorrcoef
Bmean
Csum
Dstd
Attempts:
3 left
2fill in blank
medium

Complete the code to compute the correlation matrix of a pandas DataFrame.

ML Python
import pandas as pd
data = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}
df = pd.DataFrame(data)
correlation_matrix = df.[1]()
print(correlation_matrix)
Drag options to blanks, or click blank then click option'
Acorr
Bsum
Cmean
Dstd
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly calculate the correlation between two numpy arrays.

ML Python
import numpy as np
x = np.array([1, 2, 3, 4])
y = np.array([4, 3, 2, 1])
correlation = np.corrcoef(x, [1])
print(correlation[0, 1])
Drag options to blanks, or click blank then click option'
Anp.mean
Bnp.array
Cx
Dy
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

ML Python
words = ['cat', 'house', 'tree', 'a', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 2 characters.

ML Python
words = ['apple', 'be', 'cat', 'dog']
result = { [1]: [2] for word in words if len(word) [3] 2 }
print(result)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left