Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
2fill in blank
mediumComplete 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'
Attempts:
3 left
3fill in blank
hardFix 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'
Attempts:
3 left
4fill in blank
hardFill 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'
Attempts:
3 left
5fill in blank
hardFill 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'
Attempts:
3 left