What are lazy functions and how does dask deal with them?

This recipe explains what are lazy functions and how does dask deal with them

Recipe Objective

What are lazy functions? How does dask deal with them.

In python we have something called lazy functions specially for big DataFrames we call it lazy execution of code.

Sometimes problems don't fit in the single code, or the RAM could not hold the long execution of code, sometimes dask.arrays or dask.dataframe fails to manage the long Datasets. To overcome those problems we can use dask.delayed interface in this the users can parallelize the custom algorithms.It allows users to create graphs directly with a light annotation of normal python code.

Access Product Recommendation System Project with Source Code

Step 1- Importing Libraries.

import dask

Step 2- Creating a Dask Delayed code for sample.

We will define some sample functions and then we will apply the Delay function after combining all the functions.

def increase(x): return x + 2 def triple(x): return x * 3 def divide(x,y): return y/x def add(x, y, z): return x + y +z

Step 3- Creating a sample list.

Now we will pass the list from every defined function and compute the final data.

data = [5, 10, 15, 20, 25, 30, 35, 40] y=100 output = [] for x in data: a = increase(x) b = triple(x) c = divide(x,y) d = add(a, b, c) output.append(d) total = dask.delayed(sum)(output) total

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Predictive Analytics Project for Working Capital Optimization
In this Predictive Analytics Project, you will build a model to accurately forecast the timing of customer and supplier payments for optimizing working capital.

MLOps Project to Build Search Relevancy Algorithm with SBERT
In this MLOps SBERT project you will learn to build and deploy an accurate and scalable search algorithm on AWS using SBERT and ANNOY to enhance search relevancy in news articles.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)