C2W2 error in bias assignment

Dear All,
I have run into errors on the final cell of the task. I am not sure if the particular assertion error that I am experiencing is wrong and cannot see why it is occurring. Here are my highest covariances, [[5.0277819 ]
[3.98804526]
[2.0828533 ]]
Here is the error,
—> 16 assert np.all(np.abs(highest_covariances - [5, 4, 2]) < 0.5 )
The unit tests for each individual function run correctly, up to the get_top_covariances function.
Many thanks,
Mark

@MGriff,
That assert is checking that your values for highest covariances are close to the numbers [5, 4, 2]
Each of the numbers in your list look close, but it looks like you have a list of lists instead of just a flat list like [5, 4, 2]

1 Like

Dear Wendy,

The previous error was solved with a simple flatten() of the highest_covariances output. However the top indices put out are out of order with the target indices for the next assert.

relevant_indices, highest_covariances = get_top_covariances(foo, 0, top_n=3)
assert (tuple(relevant_indices) == (3, 1, 2)), “Make sure to consider the magnitude of negative covariances”
assert np.all(np.abs(highest_covariances - [-5, 2, -0.5]) < 0.5 )
relevant_indices, highest_covariances = get_top_covariances(foo, 2, top_n=2)
AssertionError: Make sure to consider the magnitude of negative covariances

How is this working for the first example but not the second? I calculate np.abs prior to np.argsort within get_top_magnitude_indices, so feel it should be taking care of negative covariances.

Covariance matrix:
[[10.20673086 2.03248724 -0.46850328 -5.17661497]
[ 2.03248724 11.40582107 5.05519325 4.20627922]
[-0.46850328 5.05519325 9.88651003 2.11962934]
[-5.17661497 4.20627922 2.11962934 11.4730778 ]]

Top_indices:
[[2 1 0 3]
[0 3 1 2]
[0 3 2 1]
[2 1 3 0]]

Edited_top_indices:
[2 1 3 3 1 2 3 2 1 2 1 3]

Relevant_indices:
[2 1 3]

Selected_covariances:
[[10.20673086]
[ 2.03248724]
[-0.46850328]
[-5.17661497]]

Highest_covariances (masked with indices):
[-0.46850328 2.03248724 -5.17661497]

Many thanks,
Mark

@MGriff,
I think I see where the problem is. What we want to look at is how other features vary relative to our target feature. That means when we’re looking at the covariance matrix we want to look at just the one column for our target index - that shows us how each feature varies relative to the feature at that target index. We don’t want to look at the whole covariance matrix grid - just that column. I suspect that also explains why you were ending up with a list of lists originally, rather than just a list.

Look at your implementation of get_top_covariances() and try modifying it to get top magnitude indices for just the target index column, rather than the whole matrix.

2 Likes

It is working now and the purpose is clear. Thanks again for your help.
Mark

1 Like

Thanks, Wendy! Just reading this post I realized that we need to take all covariances, therefore excluding variance, or entrance of covariance_matrix[target_index][target_index]. :grin: