PCA Explained Variance Ratio

~15 mincode completion

Implement explained_variance_ratio(X) returning the ratios, largest first. Use np.linalg.eigvalsh, which is built for symmetric matrices.

Where this shows up

~15 min

3 employers weight this skill

2 big tech firms, 1 health and bio company. Top match scores 85.

Python
import numpy as np


def explained_variance_ratio(X):
    """
    Share of total variance along each principal component.

    Args:
        X: array of shape (n, d), n >= 2

    Returns:
        array of shape (d,): eigenvalue ratios of the covariance, sorted descending
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.