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

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

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.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

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.

Human Activity Recognition Using Multiclass Classification in Python
In this human activity recognition project, we use multiclass classification machine learning techniques to analyse fitness dataset from a smartphone tracker.