I’m stuck with the fifth exercise compute_pca. I see that it is troubling others as well and I’m unable to find enough help in these forums. My expected output is incorrect
The problem:
When I execute the following cell
# Testing your function
np.random.seed(1)
X = np.random.rand(3, 10)
X_reduced = compute_pca(X, n_components=2)
print("Your original matrix was " + str(X.shape) + " and it became:")
print(X_reduced)
The first and second hints for the exercise were wrong in my experience
Hints 1 and 2
* Use numpy.mean(a,axis=None) : If you set axis = 0, you take the mean for each column. If you set axis = 1, you take the mean for each row. Remember that each row is a word vector, and the number of columns are the number of dimensions in a word vector.
* Use numpy.cov(m, rowvar=True) . This calculates the covariance matrix. By default rowvar is True. From the documentation: "If rowvar is True (default), then each row represents a variable, with observations in the columns." In our case, each row is a word vector observation, and each column is a feature (variable).
As soon as I changed the mean calculation numpy.mean(a, axis=0) and covariance calculation to numpy.cov(m, rowvar=False), the unit tests passed!
Hey @MattHo,
Welcome, and we are glad that you could be a part of our community Thanks a lot for letting us know that your issue has been resolved. As for the hints, they mention the functions with their default hyper-parameters. If you read the hints completely, you will find that it has been highlighted explicitly. I hope this helps.
As for the hints, they mention the functions with their default hyper-parameters. If you read the hints completely, you will find that it has been highlighted explicitly. I hope this helps.
Thank you for attempting to clarify the problem. I appreciate your time. Now that you explained the ‘highlight’ was intended to provide context, I should understand future hints better.
Let me critique your response as I believe the hint instructions are pedagogically flawed. I read the hints completely and multiple times and it was not clear that these were the ‘default’. Also it was not clear that the ‘highlight’ was intended to indicate for the student to vary the default. I suggest a simple rewrite like so where I use an ellipsis to indicate do not change anything else.
* Use numpy.mean which takes one required parameter. You need to specify the optional argument axis for this exercise : If you set axis = 0, [...] in a word vector.
* Use numpy.cov which takes one required parameter. You need to specify the optional argument rowvar for this exercise. This calculates the [...] feature (variable).
Hey @MattHo,
Thanks a lot for the follow-up. Let me pass your suggestions to the team, and they will update the hints as they deem fit to be best for the learners.