Project - Building Spam Classifier

27 / 27

Spam Classifier - Calculate the Precision and Recall for the model

Finally, we will calculate the precision and recall for the model that we created in the previous step.

  • First, we will import precision_score and recall_score from Scikit-learn:

    from sklearn.metrics import precision_score, << your code goes here >>
  • Put the test set through the pipeline we created:

    X_test_transformed = << your code goes here >>.transform(X_test)
  • Fit our model on the test set:

    log_clf = LogisticRegression(solver="lbfgs", random_state=42), y_train)
  • Make our predictions using predict on the transformed test dataset:

    y_pred = log_clf.<< your code goes here >>(X_test_transformed)
  • Finally, we will calculate and print the Precision and Recall scores of our model:

    print("Precision: {:.2f}%".format(100 * precision_score(y_test, y_pred)))
    print("Recall: {:.2f}%".format(100 * recall_score(y_test, y_pred)))
Get Hint See Answer

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...