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

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

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.

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.

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.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in 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.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Data Science Project on Wine Quality Prediction in R
In this R data science project, we will explore wine dataset to assess red wine quality. The objective of this data science project is to explore which chemical properties will influence the quality of red wines.

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.

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.