Code Logistic Regression


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. Each \(y_i \in \ \{0,1\}\).
Assuming \(X \) and \(y\) follows a relationship which is given by following equation \begin{align} p(y=1\mid X,a, b)=\frac{1}{1+e^{-(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, b\), such that following cost function is minimized over given dataset. \begin{align} J(a_1,a_2.....a_k, b)=\frac{1}{m}*(-\sum_{i=1}^my_i*\log(\hat{p_i})-\sum_{i=1}^m(1-y_i)*\log(1-\hat{p_i})) \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