Stuck with dimensions on compute_pca

Did you ever get a response from them? Im hitting the same thing. 4 tests passing and 2 test failed.

This assignment and specifically the PCA part needs more attention.

Edit:
As is always the case I don’t find my issue until I actually make a post about it. But while I understand the mistake I made - the hint for mean was wrong.

No, I never got a reply, @joeknowsnothing.

Thats too bad. Did you finish the rest of the courses? Is it the same level of quality as this first one?

I had the same issue as most of you and after a long debugging have found my mistake which perhaps is the same for some of you.
According to the way that you implement the eig.vectors sorting, it is possible that your row/col. are inverted and you have to apply a transpose to it.

I faced the same issue as well: 4 tests passed, but 2 failed! However, after playing with my code and debugging for a while, I could solve the problem. I would strongly recommend to pay attention to the “axis” value in np.mean() and the value of “rowvar” in np.cov() functions.

In addition, you do not necessarily need to transpose the matrices at the end. Note that X_demeaned is of size [n_observations, n_features], while eigen_vecs_subset is a matrix of size [n_features, n_components], and finally you need X_reduced to be of size [n_observations, n_components], so you could easily multiply X_demeaned by eigen_vecs_subset to obtain an output of the desired shape.

1 Like

I found the problem!

Make sure that when you call the eigen_vecs_sorted you use two colons when refering to your x and y values. The last colon seemed to have thrown everyone off when using the n_components value

Hello. I can’t seem to figure out how to my the X_reduced into the right shape. Whenever, I try to multiply the transposes, I keep getting mismatches.

Right now, I get the unit test to run with 4 passes and 2 fails (similar to others).

Any help out there?

My notebook id is: twbrijcf

One additional thing to consider - in the lectures we’re told to normalize the data. In the assignment, we are only asked to mean center the data (so no division by standard deviation). I actually got stucked here, as I went straight to the normalized data. So if you got 4 out of 6, please check the data preparation as well.

1 Like

Thanks! This solved my problem.

I just passed all the tests. It seems to me that this statement in the lab is incorrect!

# transform the data by multiplying the transpose of the eigenvectors with the transpose of the de-meaned data
# Then take the transpose of that product.

I experimented a lot with transposing the vectors, but ultimately the tests passed with untransposed vectors.

1 Like

After reading carefully through the hints, which were not too clear given the incorrect default parameters that were posted for the mean and covariance calls, I had to set the np.mean axis parameter to 0 and the np.cov rowvar parameter to False. Then I was able to follow the instructions as given, and passed the unit tests

1 Like

If you are stuck at 4 pass, 2 failed issue, calculate the covariance matrix with X and not with X_demeaned. This is how I passed all the tests.

Thanks @Shantimohan_Elchuri . Process of checking vectors at various stages helped me solve the issues that i am facing.