Logistic Regression From Scratch for Loan Prediction



Hi, Freinds

I want an urgent help on implementing a logistic regression equation for the loan prediction data set. The approach given below in the provided link is just calling the model and passing it through the function for the result but I want to code my logistic regression algorithm here instead of the pre-built model. I request you to please help me out as I’ll be very much thankful to you all.


Hello @aaron11
You could implement the Logestic Regression like this -->

# Imports
from sklearn.linear_model  import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix,accuracy_score

logmodel = LogisticRegression()        #  Logistic model declaration
logmodel.fit(X_train,y_train)          #  Training model on X_train
predictions = logmodel.predict(X_test) #  Predicting o n X_test
print(confusion_matrix(y_test,predictions)) # Scores and reports



Thank you for the reply but I need the logistic regression to be worked without a library. I have found one code, will you please look into it and help me out to work with loan prediction problem?


Hi @aaron11,

I recommend you understand the Machine Learning process of training and testing before directly jumping into implementation from scratch. Try and understand the following –

  1. What is training, Log-likely hood in Machine learning?
  2. Gradient, learning rate and how weights change from initial to final state
  3. How prediciton works ?

The link you sent has complete scratch implementations of the mentioned concepts. If understood well you will have no problem implementing the same for your problem case.

The exact code change for your implementation should be done at cells 43 and 157 in the above notebook. And, I highly recommend you that you code this into a seperate file to understand what each function does so that you can compare your algorithm results from that of scikit-learn’s implementation. Let us know if you have done it. Cheers!


Please check and guide me


@AishwaryaSingh Will you please look into it and can help me out? I’ll be very much thankful to you


Hey @aaron11,

Can you share the notebook? I’ll DM you the mail ID.