Google Colab, Python, Data Science and Machine Learning

What is Google Colab? That’s our first question. The second question is, is it free to use? We’ll answer these questions in this section.

First thing first.

Google Colab is an interactive environment and it runs in the Cloud where you can write Python code and execute, seeing the result instantly.

Basically it’s to run Jupyter notebooks in the cloud. 

On the other hand, Google Colab is free.

All you need is a Gmail account to sign in so that you can save your works in the Google Drive as well as in your GitHub repository.

In addition we can use the Graphics Processing Unit or GPU for free. However, it has a limit. We can use the GPU for 12 hours continuously. 

In our previous section, we have seen how we can plot a single vector using the Matplotlib library.

Certainly we have done it locally and got an output as follows.

Matplotlib plots a single vector, when value is 6 on the x axis and 3 on the y axis, however it starts from (4, 4)
Matplotlib plots a single vector, when value is 6 on the x axis and 3 on the y axis, however it starts from (4, 4)

Let’s take a look at the code also.

import matplotlib.pyplot as plt

# a Vector can originate anywhere, yet we can set location 
X = [0]
Y = [0]

# Directional vectors 

U = [6]
V = [3]

# Creating plot
plt.quiver(X, Y, U, V, color='b', units='xy', scale=1)
plt.title('Single Vector')

# x axis limit and y axis limit
plt.xlim(-10, 10)
plt.ylim(-10, 10)

# Show plot with grid just like a graph paper
plt.grid()
plt.show()

We had run the same code and got the output instantly.

Google Colab output
Google Colab output

As we see, it gives you the output instantly. 

Moreover, we can change the value any time and test it. 

For that we don’t have to open our Jupyter notebooks, or any code editor like Visual Studio.

After all, whatever we write and test locally, we ultimately save it in the Cloud. Right? 

Advantages of using Google Colab

Google Colab allows you to save it in Google Drive, share it with fellow developers and add the file to GitHub.

One of the greatest advantages is we can test the code instantly. 

Let’s change the above code to plot the single vector in such a way that it moves in the opposite direction.

Therefore we have to change the magnitude and direction both.

As a result our new code looks the following.

import matplotlib.pyplot as plt

# a Vector can originate anywhere, yet we can set location 
X = [0]
Y = [0]

# Directional vectors 

U = [-6]
V = [-3]

# Creating plot
plt.quiver(X, Y, U, V, color='b', units='xy', scale=1)
plt.title('Single Vector')

# x axis limit and y axis limit
plt.xlim(-10, 10)
plt.ylim(-10, 10)

# Show plot with grid just like a graph paper
plt.grid()
plt.show()

As an outcome, we have the output as follows.

The arrow points in the opposite direction.

Google Colab allows to change code and gives output instantly
Google Colab allows to change code and gives output instantly

Another advantage is we don’t have to use the local system resource. 

In addition, we can save it where we want to save the file. Either in Google Drive or GitHub.

Google Colab sharing and saving options
Google Colab sharing and saving options

In this short overview we have not covered all the features here. 

But in the future as we will work more on Data Science using Machine Learning Algorithms, we’ll find that Google Colab is really helpful in every respect.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

Flutter, Dart and Algorithm

Twitter

Comments

2 responses to “Google Colab, Python, Data Science and Machine Learning”

  1. […] misconceptions that prevail and that also misguide us. Especially beginners in Data Science, or who want to study Machine Learning in […]

  2. […] the above code, we have used Google Colab and imported the TensorFlow library […]

Leave a Reply