How to parallalise execution of XGBoost and cross validation in Python?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to parallalise execution of XGBoost and cross validation in Python?

How to parallalise execution of XGBoost and cross validation in Python?

This recipe helps you parallalise execution of XGBoost and cross validation in Python

0
This python source code does the following: 1. Imports the necessary library 2. Sets up execution by permuting threads between XGB and CrossValidation 3. Evaluates the final results
In [1]:
## How to parallalise execution of XGBoost and cross validation in Python

def Snippet_190():
    print()
    print(format('How to parallalise execution of XGBoost and cross validation in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import time
    from sklearn import datasets
    from sklearn.model_selection import train_test_split, cross_val_score
    from xgboost import XGBClassifier

    # load the iris datasets
    dataset = datasets.load_wine()
    X = dataset.data; y = dataset.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)

    # Single Thread XGBoost, Parallel Thread CV
    start = time.time()
    model = XGBClassifier(nthread=1)
    results = cross_val_score(model, X, y, cv=10, scoring='neg_log_loss', n_jobs=-1)
    elapsed = time.time() - start
    print("Single Thread XGBoost, Parallel Thread CV: %f" % (elapsed))

    # Parallel Thread XGBoost, Single Thread CV
    start = time.time()
    model = XGBClassifier(nthread=-1)
    results = cross_val_score(model, X, y, cv=10, scoring='neg_log_loss', n_jobs=1)
    elapsed = time.time() - start
    print("Parallel Thread XGBoost, Single Thread CV: %f" % (elapsed))

    # Parallel Thread XGBoost and CV
    start = time.time()
    model = XGBClassifier(nthread=-1)
    results = cross_val_score(model, X, y, cv=10, scoring='neg_log_loss', n_jobs=-1)
    elapsed = time.time() - start
    print("Parallel Thread XGBoost and CV: %f" % (elapsed))

Snippet_190()
******How to parallalise execution of XGBoost and cross validation in Python******
Single Thread XGBoost, Parallel Thread CV: 3.205920
Parallel Thread XGBoost, Single Thread CV: 0.322138
Parallel Thread XGBoost and CV: 0.142706

Relevant Projects

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.

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

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.

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.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

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.

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.

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.

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.