The article “Google Colab – A Step-by-step Guide” first appeared on AlgoTrading101 blog.
Excerpt
What is Google Colab?
Google Colab is an online notebook-like coding environment that is well-suited for machine learning and data analysis.
It comes equipped with many Machine Learning libraries and offers GPU usage. It is mainly used by data scientists and ML engineers.
Link: https://colab.research.google.com
Is Google Colab free?
Yes, Google Colab is free to use and you can access all of its features to a certain degree. There is a subscription plan called Google Colab Pro that offers access to upgraded features.
These upgraded features allow the use of more processing power, RAM, and memory. You can access this plan for $9.99 per month if you come from one of the following countries:
- US
- Canada
- UK
- Germany
- France
- India
- Japan
- Thailand
- Brazil
Why should I use Google Colab?
- Google Colab is Free
- Easy to get started
- Allows access to GPUs/TPUs
- Easy to share code with others
- Easy graphical visualizations in Notebooks
Let’s go over each of the pros of Google Colab.
Firstly, it is free to use and everyone can access it. There are also some premium features if you want to utilize GPUs/TPUs with more power and fewer limitations.
Getting started with Google Colab is easy. You don’t need to install any prerequisites or have a decent PC or laptop. All you need is a browser where you’ll get a Jupyter Notebook-like environment.
Google Colab comes ready with GPUs and TPUs which can be utilized with a click of a single button. This makes Google Colab a great coding environment for machine learning practitioners.
Sharing code with Google Colab can be done through Google Drive or directly to GitHub with an in-built feature.
Being like a Jupyter Notebook, a Google Colab document allows you to run code in blocks, and intersperse these blocks with Markdown cells. It can also easily display multiple graphical outputs.
All of these features make Google Colab a phenomenal asset when it comes to collaborative, data science, machine learning, and data analysis projects.
Why shouldn’t I use Google Colab?
- GPU/TPU usage is limited
- Not the most powerful GPU/TPU setups available
- Not the best de-bugging environment
- It is hard to work with big data
- Have to re-install extra dependencies every new runtime
GPU/TPU usage is not endless with Google Colab as resources aren’t infinite. The free version lasts for 12 hours of continuous usage and is not very tolerant with inactivity, whilst the pro version allows 24 hours of continuous usage with greater tolerance.
The free version of Google Colab allows the usage of a K80 GPU while the Pro version allows a T4 or P100 GPU. For most of you, these GPUs are way more powerful than the ones you have, but for more money we can get even better ones (e.g. AWS).
Being a Notebook environment, it will be harder to catch bugs in your code before running it.
As big datasets need to fit in a Google drive, it can be difficult to deal with them because you are limited to 15 GB of free space with a Gmail id.
Lastly, you’ll have to (re)install any additional libraries you want to use every time you (re)connect to a Google Colab notebook. A good thing is that it comes equipped with pre-installed libraries that are often used.
What are the alternatives to Google Colab?
Google Colab can be replaced with other platforms that can be more suitable for your needs. Here are some of them:
- Jupyter Notebook
- Kaggle
- Azure Notebooks
- Amazon SageMaker
- Paperspace Gradient
- FloydHub
Does Google Colab support Python?
Yes, Google Colab supports Python (and as of October 2019 only allows the creation of Python 3 notebooks), though in some cases with further tinkering it might be possible to get R, Swift, or Julia to work.
Have in mind that since the 1st January 2020, Python 2 is no longer supported.
How do I get started with Google Colab?
There are several ways to get started with Google Colab and we will go over each of them. All approaches are quite easy and it depends on what you want to start working on (i.e. fresh notebook or GitHub repository).
The first way is to go over to your Google Drive account. In the top left corner select “New”, then “More” in the drop-down panel, and then “Google Collaboratory”.
To open an existing Google Colab document simply right click on it –> Open With –> Google Collaboratory. You can also load other people’s Google Colab documents if you share a google drive with them.
To import/open files directly from GitHub you will need the Open in Colab chrome extension. Add it to your chrome, then navigate over to the notebook you want to open in Github, click on your browser’s Extensions tab, then click Open in Colab.
As the extension is new and is still being worked on I’d advise waiting a bit for it to get polished.
Another way is to go to this link and click the “New Notebook” button. You can also see that you have access to Google Colab examples, Recent notebooks, Google Drive, GitHub, and you can upload your own notebook.
After opening up a new Notebook you can do a couple of things with it. The first thing is to give it a name in the upper left corner. In the upper right corner, you can click on the Settings icon.
When in settings you can change your theme to dark, set your editor key bindings and colors, change the font size, and more. Be sure to customize these features so they suit your preferences.
Now, let us get acquainted with some of the most used shortcuts so we can save ourselves some time (for Mac users CTRL == Command):
- Command Pallete – Ctrl+Shift+P
- Add a comment – Ctrl+Alt+M
- Convert to text cell – Ctrl+M M
- Add a new cell below – Ctrl+B B
- Run all cells – Ctrl+F9
- Run the current cell – Ctrl+Enter
- Save Notebook – Ctrl+S
- Show keyboard shortcuts – Ctrl+M H
All shortcuts can be edited to suit your needs.
On the left taskbar, you can view your Notebook’s table of contents that shows all the Markdown headers in a structured way, useful code snippets, files, and a search and replace tool.
To start coding, in the upper right side you may see the connect button so be sure to click it. When connected you will see something like this:
Now that we know how to use some of the main features of Google Colab, we are ready to start working on a problem. I believe that this is the best way to get acquainted with new environments and learn some new things as a bonus.
How do I import libraries/install dependencies in Google Colab?
Importing libraries and installing dependencies in Google Colab is quite easy. You need to use your usual !pip install
and import
commands followed by the libraries/dependencies name.
A great thing about Google Colab is that it comes with many preinstalled dependencies that are often used.
Any installations only remain for the duration of your session, so if you close the session/notebook, you’ll have to run inline installations whenever you open your project again.
You can check which version of a library you’re using with !pip show
. For example, to check which version of TensorFlow you are using you would use !pip show tensorflow
To upgrade an already installed library to the latest version, use !pip install --upgrade tensorflow
And finally to install a specific version, use !pip install tensorflow==1.2
Visit AlgoTrading101 for instructions on enabling GPU/TPU usage in Google Colab.
Disclosure: Interactive Brokers
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from AlgoTrading101 and is being posted with its permission. The views expressed in this material are solely those of the author and/or AlgoTrading101 and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.