How to check models recall score using cross validation in Python?
MODEL SELECTION DATA CLEANING PYTHON DATA MUNGING MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

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

0

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 = cancer.data y = cancer.target

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]

0.9160015649452269

0.03188194241586345

Relevant Projects

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

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.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

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.

Mercari Price Suggestion Challenge Data Science Project
Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.