How to check models accuracy using cross validation in Python?
MODEL SELECTION

How to check models accuracy using cross validation in Python?

How to check models accuracy using cross validation in Python?

This recipe helps you check models accuracy using cross validation in Python

0
This data science python source code does the following: 1. Difference between train test split and Cross Validation. 2 .Hyper-parameter tunes Cross Validation function. 3. Implements CrossValidation on Decision tree model and visualizing the final output.
In [1]:
## How to check model's accuracy using cross validation in Python
def Snippet_132():
    print()
    print(format('How to check model\'s accuracy using cross validation in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn.model_selection import cross_val_score
    from sklearn.tree import DecisionTreeClassifier
    from sklearn.datasets import make_classification

    # Generate features matrix and target vector
    X, y = make_classification(n_samples = 10000,
                               n_features = 3,
                               n_informative = 3,
                               n_redundant = 0,
                               n_classes = 2,
                               random_state = 42)

    # Create Decision Tree model
    dtree = DecisionTreeClassifier()

    # Cross-validate model using accuracy
    print(); print(cross_val_score(dtree, X, y, scoring="accuracy", cv = 7))
    mean_score = cross_val_score(dtree, X, y, scoring="accuracy", cv = 7).mean()
    std_score = cross_val_score(dtree, X, y, scoring="accuracy", cv = 7).std()
    print(); print(mean_score)
    print(); print(std_score)

Snippet_132()
**********How to check model's accuracy using cross validation in Python**********

[0.92517483 0.91398601 0.93697479 0.92647059 0.92927171 0.92717087
 0.92927171]

0.926103868120675

0.006990971894539273

Relevant Projects

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

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.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

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.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

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.