Compute the sample covariance matrix without using np.cov. First center each feature:
Xc=X−μThen compute:
Σ=N−1XcTXcHere, X has N samples and D features, μ is the vector of feature means, Xc is the centered data, and Σ is the D×D sample covariance matrix. Return Σ as a NumPy array.
Input: X = [[1, 2], [2, 3], [3, 4]]
Output: [[1.0, 1.0], [1.0, 1.0]]
Explanation: Both features vary together by the same amount after centering.
Input: X = [[1, 0], [0, 1]]
Output: [[0.5, -0.5], [-0.5, 0.5]]
Use X - np.mean(X, axis=0) to center every feature.
Use centered.T @ centered before dividing by X.shape[0] - 1.
Sign in to take notes on this problem
Accepts: array
Compute the sample covariance matrix without using np.cov. First center each feature:
Xc=X−μThen compute:
Σ=N−1XcTXcHere, X has N samples and D features, μ is the vector of feature means, Xc is the centered data, and Σ is the D×D sample covariance matrix. Return Σ as a NumPy array.
Input: X = [[1, 2], [2, 3], [3, 4]]
Output: [[1.0, 1.0], [1.0, 1.0]]
Explanation: Both features vary together by the same amount after centering.
Input: X = [[1, 0], [0, 1]]
Output: [[0.5, -0.5], [-0.5, 0.5]]
Use X - np.mean(X, axis=0) to center every feature.
Use centered.T @ centered before dividing by X.shape[0] - 1.
Sign in to take notes on this problem
Accepts: array