I read a topic about the similar question but still cannot figure out how to write the code in this function. At the beginning I faced some assertion errors. I managed to adjust the code to fulfill the test unit. Although the running test passed, but I still suspect that it might just be a coincidence. Here is what I wrote:
covariance_matrix = covariance_matrix_from_examples(classification_changes)
# print(covariance_matrix.shape)
# print(covariance_matrix)
top_magnitude_indices = get_top_magnitude_indices(covariance_matrix[target_index])
# print(top_magnitude_indices.shape)
# print(top_magnitude_indices)
relevant_indices = top_magnitude_indices[1:top_n + 1]
# print(relevant_indices)
highest_covariances = covariance_matrix[target_index][relevant_indices]
# print(highest_covariances.shape)
# print(highest_covariances)
The other lines seem plausible to me , but the line of relevant_indices seems to be wrong. I do not know why [1:top_n+1] is used here as well but it just makes the program works. I do not know where and how to use the function remove_from_list so I just leave it there without use.
Please solve my question and thank you.