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(θ).

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.

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.

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：

Favorite(0) Share
 andersoncf1 MVE Author Created Jul 22, 2021 01:44:42 .pcb{margin-right:0} .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Thanks for sharing! Well done View more x convention： csk99 Created Jul 22, 2021 11:27:00 (0) (0)   x
 Laiheang Created Jul 22, 2021 03:40:37 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } View more x convention： csk99 Created Jul 22, 2021 22:14:54 (0) (0)   x azkasaqib Created Jul 27, 2021 16:19:16 (0) (0)   x
 Navin_kay Created Jul 22, 2021 05:04:16 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } helpful post View more x convention： csk99 Created Jul 22, 2021 11:27:10 (0) (0)   x LilStylz237 Created Jul 22, 2021 21:02:26 (0) (0) Really helpful   x azkasaqib Created Jul 27, 2021 16:19:22 (0) (0)   x
 Vlada85 MVE Author Created Jul 22, 2021 16:22:44 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Very interesting article! View more x convention：
 LilStylz237 Moderator Created Jul 22, 2021 21:02:00 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Very interesting dear View more x convention： csk99 Created Jul 22, 2021 22:14:20 (0) (0) Thanks my friend   x
 wissal MVE Created Jul 25, 2021 11:14:54 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Interesting knowledge View more x convention：
 Unicef MVE Created Jul 27, 2021 09:27:18 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Good Share View more x convention：
 MahMush Moderator Author Created Jul 27, 2021 13:53:08 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } nice post ... waiting for more ML posts by you View more x convention：
 azkasaqib Created Jul 27, 2021 16:19:29 .pcb table{table-layout:auto;} div#jdc_suspicious_threads{ background: #fcf5d8; text-align: center; font-size: 12px; } Cool View more x convention：
12
Back to list

Comment

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

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