How to check models recall score using cross validation in Python?

How to check models recall score using cross validation in Python?

How to check models recall score using cross validation in Python?

This recipe helps you check models recall score using cross validation in Python


Recipe Objective

To test how our model is performing we need a scoring metric and for classifier we can use recall score. Here we will using cross validation to split the data into various set and test the model on a single set while training it on other.

So this is the recipe on how we can check model"s recall score using cross validation in Python.

Step 1 - Import the library

from sklearn.model_selection import cross_val_score from sklearn.tree import DecisionTreeClassifier from sklearn import datasets

We have only imported cross_val_score, DecisionTreeClassifier and datasets which is needed.

Step 2 - Setting up the Data

We have imported an inbuilt breast cancer dataset to train the model. We have stored data in X and target in y. cancer = datasets.load_breast_cancer() X = y =

Step 3 - Model and cross validation

We have used DecisionTreeClassifier as a model and used cross validation. In cross validation we have passed model, scoring metric as recall and cv as 5.
we have calculated mean and standard deviation of cross validation score. dtree = DecisionTreeClassifier() print(cross_val_score(dtree, X, y, scoring="recall", cv = 5)) mean_score = cross_val_score(dtree, X, y, scoring="recall", cv = 5).mean() std_score = cross_val_score(dtree, X, y, scoring="recall", cv = 5).std() print(mean_score) print(std_score) So the output comes

[0.90277778 0.93055556 0.95774648 0.95774648 0.84507042]



Relevant Projects

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Census Income Data Set Project - Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based on census data.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.