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

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

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.

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.

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.

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

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.

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.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

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.