Module 2 of 25 · TensorFlow & Keras · Intermediate

Setting Up Your Environment

Duration: 7 min

This module will guide you through the essential steps required to set up your Python environment for machine learning projects using TensorFlow and Keras. You'll learn how to install necessary libraries, configure your development environment, and verify your setup to ensure everything is working correctly. This foundational knowledge is crucial for building, training, and deploying neural networks effectively.

Installing TensorFlow and Keras

TensorFlow is an open-source machine learning framework developed by Google, and Keras is a high-level API that runs on top of TensorFlow, making it easier to build and train machine learning models. To get started, you need to install these libraries using pip, Python's package manager. This section will cover the installation process and how to verify that TensorFlow and Keras are correctly installed.

import tensorflow as tf
from tensorflow import keras

# Verify TensorFlow installation
print(f'TensorFlow Version: {tf.__version__}')

# Verify Keras installation
print(f'Keras Version: {keras.__version__}')

Try it in Google Colab: Open in Colab

TensorFlow Version: 2.x.x
Keras Version: 2.x.x

Setting Up a Virtual Environment

Using a virtual environment is a best practice for Python development, as it allows you to manage dependencies for different projects separately. This section will guide you through creating a virtual environment using venv, activating it, and installing TensorFlow and Keras within this isolated environment.

#!/bin/bash

# Create a virtual environment
python3 -m venv tf_env

# Activate the virtual environment
source tf_env/bin/activate

# Install TensorFlow and Keras
pip install tensorflow

💡 Tip: Always activate your virtual environment before starting your machine learning project to ensure that the correct versions of libraries are used.

❓ Which command is used to verify the installation of TensorFlow?

❓ What is the primary benefit of using a virtual environment in Python development?

← Previous Continue interactively → Next →

Related Courses