Inverse Transform After Prediction

~10 mincode completion

Implement inverse_standardize(predictions, mu, sigma) that maps scaled predictions back to the original scale.

Examples

Scaled 0 maps to mu, +1 maps to mu+sigma, -1 maps to mu-sigma

Input
inverse_standardize([0, 1, -1], 100, 20)
Output
[100, 120, 80]

Identity case: sigma=1, mu=0 leaves predictions unchanged

Input
inverse_standardize([3, -2, 0.5], 0, 1)
Output
[3, -2, 0.5]

All-zero predictions map to mu regardless of sigma

Input
inverse_standardize([0, 0], 50, 10)
Output
[50, 50]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

A common slip here: subtracted mu instead of adding.

Requirements

  • predictions: 1D array of standardized predictions

  • mu: Mean used during forward standardization

  • sigma: Std dev used during forward standardization

  • Return 1D float array in the original scale.

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

8 employers weight this skill

3 AI product companies, 2 big tech firms, 2 enterprise vendors, 1 defense company. Top match scores 87.

Python
import numpy as np

def inverse_standardize(predictions: np.ndarray, mu: float, sigma: float) -> np.ndarray:
    """
    Reverse the standardization: y_original = y_scaled * sigma + mu.

    Args:
        predictions: 1D array of standardized predictions
        mu:          Mean used during forward standardization
        sigma:       Std dev used during forward standardization

    Returns:
        1D float array in the original scale.
    """
    # 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.