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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Build a Music Recommendation Algorithm using KKBox's Dataset
Music Recommendation Project using Machine Learning - Use the KKBox dataset to predict the chances of a user listening to a song again after their very first noticeable listening event.

End-to-End Snowflake Healthcare Analytics Project on AWS-1
In this Snowflake Healthcare Analytics Project, you will leverage Snowflake on AWS to predict patient length of stay (LOS) in hospitals. The prediction of LOS can help in efficient resource allocation, lower the risk of staff/visitor infections, and improve overall hospital functioning.

Linear Regression Model Project in Python for Beginners Part 1
Machine Learning Linear Regression Project in Python to build a simple linear regression model and master the fundamentals of regression for beginners.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

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

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

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.

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.

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.