Using the logistic regression algorithm for the classifiers challenge

In this section, we will see how we can use the logistic regression algorithm for the classifiers challenge:

  1. First, let's instantiate a logistic regression model and train it using the training data:
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifier.fit(X_train, y_train)
  1. Let's predict the values of the test data and create a confusion matrix:

y_pred = classifier.predict(X_test)
cm = metrics.confusion_matrix(y_test, y_pred)
cm

We get the following output upon running the preceding code:

  1. Now, let's look at the performance metrics:
accuracy= metrics.accuracy_score(y_test,y_pred)
recall = metrics.recall_score(y_test,y_pred)
precision = metrics.precision_score(y_test,y_pred)
print(accuracy,recall,precision)
  1. We get the following output upon running the preceding code:

Next, let's look at SVM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset