Got it

Vectorization: What a powerful asset for Machine learning

Latest reply: Dec 18, 2021 16:21:46 576 20 8 0 0

Vectorization: What a powerful asset  for Machine learning

As you already know Machine learning (ML), a sub-field of Artificial Intelligence helps us build machines that are able to learn without being explicitly programmed.

To be able to do so, ML, more precisely ML algorithms (Logistic Regression, linear regression … ) need a huge amount of data to be trained on.

The training process is generally done finding the model parameters that minimize a certain cost function.

Let’s take the Linear Regression algorithm as an example.

Recall the Linear Regression model prediction is  y^ = θ0 + θ1x1 + θ2x2 + + θnxn.

The gradient descent algorithm is used to find the optimal Parameters so as to minimize the cost function J(θ).

 

 

cost_function

In the above expression y(i) represent the ith  label of training data set while  y^(i) represent the predicted value from our model; m represent the number of training samples and n the number of features.

To compute J(θ), the classical approach is to write a for loop starting at i=0 to m which can be really high (from 100 to even thousands ).

This approach is really slow, and inefficient when the data set becomes very huge especially in the era of Deep learning.

That’s the reason why we need vectorization.

So, what’s vectorization ?

Vectorization is an optimization technique used to make our code run faster by removing explicit for loop.

One of the top libraries that uses the vectorization approach is NumPy for Numerical Computing.

Let’s see a concrete example of vectorization using NumPy and Jupyter.

 

vector1

In this first picture we’re trying to make an element-wise product of two  (1,50000) lists containing numbers from 0 to 49999.

First of all we try the for loop approach and measure how many does it takes to compute such a product.

The  second approach we choose to create 2 n-dimensional arrays ranging from 0 to 49999 and we use np.multiply () function to do the element-wise product.

vector2

 

In conclusion we can notice that the vectorized approach takes approximately 23 times less time to output the results. That’s the incredible power of vectorization.But Not only NumPy implements vectorization but also TensorFlow, Mindspore, Octave…

 

 


  • x
  • convention:

andersoncf1
MVE Author Created Jul 22, 2021 01:44:42

Thanks for sharing! Well done
View more
  • x
  • convention:

csk99
csk99 Created Jul 22, 2021 11:27:00 (0) (0)
 
Laiheang
Created Jul 22, 2021 03:40:37

Vectorization: What a powerful asset  for Machine learning-4045405-1
View more
  • x
  • convention:

csk99
csk99 Created Jul 22, 2021 22:14:54 (0) (0)
 
azkasaqib
azkasaqib Created Jul 27, 2021 16:19:16 (0) (0)
 
Navin_kay
Created Jul 22, 2021 05:04:16

helpful post
View more
  • x
  • convention:

csk99
csk99 Created Jul 22, 2021 11:27:10 (0) (0)
 
LilStylz237
LilStylz237 Created Jul 22, 2021 21:02:26 (0) (0)
Really helpful  
azkasaqib
azkasaqib Created Jul 27, 2021 16:19:22 (0) (0)
 
Vlada85
MVE Author Created Jul 22, 2021 16:22:44

Very interesting article!
View more
  • x
  • convention:

LilStylz237
Moderator Created Jul 22, 2021 21:02:00

Very interesting dear
View more
  • x
  • convention:

csk99
csk99 Created Jul 22, 2021 22:14:20 (0) (0)
Thanks my friend  
wissal
MVE Created Jul 25, 2021 11:14:54

Interesting knowledge
View more
  • x
  • convention:

Unicef
MVE Created Jul 27, 2021 09:27:18

Good Share
View more
  • x
  • convention:

MahMush
Moderator Author Created Jul 27, 2021 13:53:08

nice post ... waiting for more ML posts by you
View more
  • x
  • convention:

azkasaqib
Created Jul 27, 2021 16:19:29

Cool
View more
  • x
  • convention:

12
Back to list

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.