Linear Regression Prediction

MediumMachine LearningMathArrayMatrix

Description

Given a weight vector w, a bias b, and a 2D array X of feature rows, return the linear-regression predictions: for each row, the dot product of w with the row plus b. Round each result to 4 decimal places.

Examples

Input:[1,2], 0, [[1,1],[2,2]]
Output:[3,6]
Explanation:

Each prediction is the weighted sum of that row’s features plus the shared bias term.

Input:[1], 0, [[5],[10]]
Output:[5,10]
Explanation:

Each prediction is the weighted sum of that row’s features plus the shared bias term.

Input:[2,-1], 1, [[3,4],[1,1]]
Output:[3,2]
Explanation:

Each prediction is the weighted sum of that row’s features plus the shared bias term.

Constraints

  • 1 ≤ rows ≤ 10⁴
  • each row length equals w length

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.