How to do hyperparameter tuning with Dask?

This recipe helps you do hyperparameter tuning with Dask

Recipe Objective

How to do hyperparameter tuning with Dask

The hyperparameters controls the quality of the predictions made by models. For example, if learning rate is too small the model will take too much time to learn.

#!pip install dask_ml #!pip install dask distributed --upgrade

Learn About the Application of ARCH and GARCH models in Real-World 

Step 1- Importing Libraries

We will have to import multiple libraries to do the tuning of our hyper parameters

from dask.distributed import Client from dask_ml.datasets import make_classification from dask_ml.model_selection import train_test_split from sklearn.linear_model import SGDClassifier from dask_ml.model_selection import HyperbandSearchCV from scipy.stats import uniform, loguniform

Step 2- Instantiating Client.

We will create the client and divide the dataset into train and test.

client = Client() x, y = make_classification(chunks=20, random_state=0) xtrain, xtest, ytrain, ytest = train_test_split(x, y)

Step 3- Instantiating SGD classifier.

We will instantiate SGDClassifier with its parameters.

cls = SGDClassifier(tol=1e-3, penalty='elasticnet', random_state=0)

Step 4- Initializing loss parameters.

We will define the learning rate and L1 loss.

parameters = {'alpha': loguniform(1e-2, 1e0), 'l1_ratio': uniform(0, 1)}

Step 5- Initializing HyperbandSearchCV

We will use the HyperbandSearchCV and insert classifier and parameter model in it to get the best parameters for the model.

search = HyperbandSearchCV(cls, parameters, max_iter=81, random_state=0) search.fit(xtrain, ytrain, classes=[0, 1]) print(search.best_params_) print(search.best_score_) print(search.score(xtest, ytest))

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

End-to-End ML Model Monitoring using Airflow and Docker
In this MLOps Project, you will learn to build an end to end pipeline to monitor any changes in the predictive power of model or degradation of data.

Build a CNN Model with PyTorch for Image Classification
In this deep learning project, you will learn how to build an Image Classification Model using PyTorch CNN

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

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.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction