In this section, we will see how we can use the logistic regression algorithm for the classifiers challenge:
- 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)
- 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:
- 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)
- We get the following output upon running the preceding code:
Next, let's look at SVM.