How to Use Google Colab for Machine Learning and Deep Learning: A Step-by-Step Beginner’s Guide

Google Colab workflow for Python, machine learning, deep learning, notebooks, and model training

Google Colab is one of the easiest ways to start experimenting with Python, machine learning, and deep learning.

It is a hosted Jupyter Notebook environment, so you can write and execute Python directly in a web browser without setting up a complete development environment on your computer. Google also provides access to accelerated hardware such as GPUs and TPUs, although availability and usage limits can vary.

What We Will Do

This guide follows a simple workflow:

Open Colab → Create Notebook → Run Python → Machine Learning → Deep Learning → Save Your Work

Step 1: Open Google Colab

Open Google Colab while signed into your Google account.

Create a new notebook.

The notebook contains cells. A code cell runs Python, while a text cell can contain explanations and headings.

Step 2: Rename the Notebook

Give the notebook a useful name such as:

AI_ML_DL_Guide.ipynb

Colab notebooks use the standard Jupyter .ipynb format and can be stored in Google Drive.

Step 3: Test the Python Environment

Run:

import sys

print(sys.version)

You can also test a basic command:

print("Google Colab is ready!")

Step 4: Check or Install Libraries

Colab already includes many commonly used libraries.

Check scikit-learn:

import sklearn

print(sklearn.__version__)

Check TensorFlow:

import tensorflow as tf

print(tf.__version__)

If a required package is missing, it can normally be installed inside a notebook:

!pip install package_name

Google recommends generally using the latest Colab runtime and installing specific package versions in the notebook when a project requires them.

Step 5: Run a Machine-Learning Example

Use the Iris dataset with k-NN:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

X, y = load_iris(return_X_y=True)

X_train, X_test, y_train, y_test = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42,
    stratify=y
)

model = KNeighborsClassifier(n_neighbors=3)

model.fit(X_train, y_train)

accuracy = model.score(X_test, y_test)

print("Accuracy:", accuracy)

The model learns from the training data and is then evaluated using examples it did not use during training.

Step 6: Understand the Workflow

The example follows:

Dataset → Train/Test Split → Model → Training → Evaluation

Separating training and testing data helps us evaluate how the model performs on unseen examples.

Step 7: Run a Deep-Learning Example

TensorFlow can load the MNIST dataset directly:

import tensorflow as tf

(x_train, y_train), (x_test, y_test) = (
    tf.keras.datasets.mnist.load_data()
)

x_train = x_train / 255.0
x_test = x_test / 255.0

model = tf.keras.Sequential([
    tf.keras.Input(shape=(28, 28)),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(64, activation="relu"),
    tf.keras.layers.Dense(10, activation="softmax")
])

model.compile(
    optimizer="adam",
    loss="sparse_categorical_crossentropy",
    metrics=["accuracy"]
)

model.fit(x_train, y_train, epochs=3)

model.evaluate(x_test, y_test)

TensorFlow itself provides beginner tutorials as Colab notebooks and uses the same basic pattern of loading a dataset, building a neural network, training it, and evaluating accuracy.

Step 8: Do You Need a GPU?

For these small examples, a GPU is not necessary.

For larger deep-learning workloads, Colab can provide optional accelerated runtimes.

You can check the available runtime settings through:

Runtime → Change runtime type

If you are not actually using GPU computation, Google recommends using a standard runtime instead of consuming GPU resources unnecessarily.

Step 9: Save Your Work

Colab notebooks can be stored in Google Drive and shared similarly to other Drive files.

It is also possible to download the notebook in .ipynb format.

Remember that the runtime itself is temporary. Files and libraries installed only inside the virtual machine may disappear after the runtime is deleted, so installation and setup commands should be kept in the notebook when reproducibility matters.

Step 10: Organise a Good Notebook

A useful beginner notebook might contain:

  1. Project objective
  2. Imports
  3. Dataset loading
  4. Data preparation
  5. Model creation
  6. Training
  7. Evaluation
  8. Results
  9. Conclusions

Use Markdown cells to explain what each section does.

This makes your notebook easier to understand, reproduce, and share.

Google Colab or Visual Studio Code?

Google Colab is especially useful when you want:

  • No local installation
  • Quick experiments
  • Browser-based notebooks
  • Easy notebook sharing
  • Optional access to accelerated hardware

Visual Studio Code may be better when you need greater control over files, environments, debugging, Git, or larger software projects.

Many AI developers use both depending on the task.

Final Thoughts

Google Colab removes much of the setup required before you can begin experimenting with machine learning and deep learning.

The basic workflow is:

Create Notebook → Load Data → Build Model → Train → Evaluate → Save

This makes Colab especially useful for learning, testing ideas, and creating reproducible AI notebooks.

Wise up to AI. Learn it. Use it. Grow with it.

References and Further Reading

Google (n.d.) Google Colab Frequently Asked Questions. Google Colaboratory. Available at: Google Colab – Frequently Asked Questions (Accessed: 16 September 2026).

Google (n.d.) Frequently Asked Questions – Past Runtime Versions. Google Colaboratory. Available at: Google Colab – Runtime Versions documentation (Accessed: 16 September 2026).

TensorFlow (2024) TensorFlow 2 Quickstart for Beginners. TensorFlow Core. Available at: TensorFlow – TensorFlow 2 Quickstart for Beginners (Accessed: 16 September 2026).

Scikit-learn Developers (n.d.) train_test_split. Scikit-learn Documentation. Available at: Scikit-learn – train_test_split documentation (Accessed: 16 September 2026).

Scikit-learn Developers (n.d.) KNeighborsClassifier. Scikit-learn Documentation. Available at: Scikit-learn – KNeighborsClassifier documentation (Accessed: 16 September 2026).