Linear Prediction

Easy
~12 min
code completion

Linear Prediction

A linear model makes predictions with a simple dot product plus a bias:

where:

  • is the feature matrix of shape (m, n)
  • is the weight vector of shape (n,)
  • is the scalar bias (intercept)
  • This is the forward pass of linear regression.

    Your task:

    Implement linear_predict(X, weights, bias) that returns the prediction vector of shape (m,).

    Example Tests

    2x2 matrix with equal weights and bias

    Input: {"X":[[1,2],[3,4]],"bias":1,"weights":[0.5,0.5]}

    Expected: [2.5,4.5]

    3 samples, integer weights, no bias

    Input: {"X":[[1,0],[0,1],[1,1]],"bias":0,"weights":[2,3]}

    Expected: [2,3,5]

    Negative weights

    Input: {"X":[[2,3]],"bias":5,"weights":[-1,2]}

    Expected: [9]

    Sign in to solve this problem

    You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.