Code Linear Regression Algorithm


You are given a pair of data points \( (X,y) \), where \(X\) is a list of \( (N , K ) \) and \(y\) is a list of \(N\) elements. Assuming \(X\) and \(y\) follows a linear relationship which is given by following equation
\begin{align} \hat{y} = a_1*x_1 + a_2*x_2 .... a_k*x_k + b \end{align}

Write a program to estimate values of \( a_1, a_2, .. a_k \) and \(b\), such that following cost function is minimized over a given dataset. \begin{align} J(a_0,a_1...a_k,b)=\frac{1}{2*N}*\sum_{i=1}^N( y_i-a_1*x_{1i} - a_2*x_{2i} ....-a_k*x_{ki}-b)^2 \end{align} Inputs
  • \( X \) : \((N , K )\) List
  • \(y\) : List of \(n\) elements
  • num_iteration : number of training steps
  • learning_rate: step size
Outputs
  • \(a\) : list of \(K\) parameters
  • \(b\) : scalar value


Code Output