Logistic regression

machine_learning

#1

Hi All,

below is the code used for building logistic regression. please help in in understanding the code.

from sklearn.linear_model import LogisticRegression # ----importing libraries

log=LogisticRegression(penalty=‘l2’,C=.01) #--------?
log.fit(X_train_scale,Y_train) #----------building the model

we are not predicting with test data with the above model and then comparing the accuracy in next line bit confused pls need your inputs

Checking the model’s accuracy

accuracy_score(Y_test,log.predict(X_test_scale))
Out : 0.75

regards,
Tony


#2

Hello @tillutony,

To define a machine learning model with scikit-learn, you have to follow specific steps

  • STEP 1: Import the algorithm you want to run
  • STEP 2: Define parameters that you want your machine learning model to have
  • STEP 3: Train the model
  • STEP 4: Test the model

For eg.

# step 1
from sklearn.linear_model import LogisticRegression

# step 2
log=LogisticRegression(penalty='l2',C=.01)

# step 3
log.fit(X_train_scale,Y_train)

# step 4
log.predict(X_test)

Hope this helps!


#3

Thanks. jalFaizy

step 4
log.predict(X_test) here we are not calling the model log.fit which we have created in step 3
and
What is penalty=‘l2’,C=.01)#--------kindly explain.

Regards,
Tony


#4

HI tillutony,

In the step 3rd, we have fit the model(log) on train so after training this model, we can refer this trained model again with the name log.

Here is the link for parameters in sklearn LogisticRegression.

Regards,
Ankit Gupta