Redirect Chapter 1: Foundations: Data, AI & Your Toolchain | AI Fundamentals
← Back to Tutorials Chapter 1

Foundations: Data, AI & Your Toolchain

The Big Picture: Data Science, ML, DL & NLP

Before writing a single line of code, it helps to know how the fields you are about to learn fit together. Think of them as concentric circles.

Simple memory hook: Data science collects and interprets data; ML learns from data; DL learns from data using very large neural networks; NLP does all of this for language. A project can easily live in all four circles at once.

Why Python is the Language of AI

Python dominates this world because it is easy to read and comes with a huge ecosystem of scientific libraries such as NumPy, Pandas, Matplotlib, scikit-learn, and TensorFlow. Your job in this book is to become fluent in the core language first, because every AI library you meet later is just Python.

Installing Anaconda

Anaconda is a free distribution of Python that bundles the interpreter, hundreds of scientific packages, and the conda package manager in one installer. It avoids the classic beginner pain of manually installing NumPy, Matplotlib and friends one at a time.

  1. Visit the official Anaconda download page and choose the installer for your operating system (Windows, macOS, or Linux).
  2. Run the installer. On Windows, the default options work well for beginners, but take note of the installation folder so you can find it later.
  3. After installation finishes, open a fresh terminal (or Anaconda Prompt) and type python --version. You should see a Python version number in response.
  4. Launch a notebook or the base environment to confirm everything works before moving on.
Heads-up: If the message conda is not recognized appears, skip ahead to the PATH section below. It is one of the most common first-day hurdles and the fix is simple.

Getting Started with VS Code

VS Code is a free, lightweight editor that is ideal for AI work. Once installed, add these things to make it productive:

A good workflow is: write a script in the editor, press the run button, and read the output in the integrated terminal. Keep the Explorer sidebar open so your projects stay organised.

Virtual Environments: Why You Need Them

A virtual environment is an isolated copy of Python with its own installed packages. Different projects can therefore use different library versions without breaking each other. If project A needs NumPy 1.x and project B needs NumPy 2.x, each keeps its own copy happily inside its own environment.

Option 1: conda environments

Anaconda users create environments with conda:

conda create --name ai-course python=3.11
conda activate ai-course
conda install numpy pandas matplotlib

Option 2: python -m venv

If you installed Python directly (no Anaconda), the built-in venv module does the job:

python -m venv myenv
myenv\Scripts\activate
pip install numpy

On macOS and Linux the activate command is source myenv/bin/activate.

Option 3: pipenv

pipenv combines environment creation and dependency tracking in one tool. It keeps a Pipfile that records your packages:

pip install pipenv
pipenv install pandas
pipenv shell

Fixing "conda is not recognized"

This error simply means the operating system cannot find the conda command because its folder is not listed in the system PATH. PATH is the list of folders the system searches whenever you type a command.

  1. Find the folder containing conda.exe. With a typical Anaconda install on Windows it lives inside the Scripts sub-folder of your Anaconda folder.
  2. Open the Windows search box, type "environment variables", and choose Edit the system environment variables.
  3. Click Environment Variables, select Path in the user list, then click Edit and New to add the Scripts folder path.
  4. Click OK everywhere, then close and reopen the terminal. Run conda --version to confirm the fix.

On macOS and Linux, add the equivalent line to your shell profile file:

export PATH="/path/to/anaconda3/bin:$PATH"
Tip: After editing PATH you must start a brand-new terminal. Old terminals still carry the outdated environment and will keep showing the same error.

Python Basics: Syntax and Semantics

Every programming language has two layers: syntax is the grammar of the language (what the code looks like), and semantics is the meaning (what the code does).

Indentation

Python uses indentation instead of curly braces to mark blocks. Every line inside a block must be indented with the same number of spaces:

score = 82
if score >= 70:
    print("You passed")   # indented: inside the if
print("Thanks")            # not indented: outside the if

Comments

A comment is text the interpreter ignores. Use # for a line comment and triple quotes for a multi-line docstring-style comment:

# this line does nothing
name = "Ada"   # inline comments explain the line
"""This is a longer comment
that spans several lines."""

Statements vs Expressions

An expression is any piece of code that produces a value, such as 3 * 4 or "hi" + " there". A statement is an instruction that performs an action, such as print(...), an if block, or an assignment. Expressions appear inside statements all the time.

Dynamic Typing

Python decides variable types at run time, so you never declare them. The same name can hold an integer and later a string:

value = 10      # an integer
value = "ten"   # now a string - perfectly legal
print(value)

This flexibility is convenient but means you must keep track of what each variable holds, because mistakes only surface when the code runs.

Exercise: Create a virtual environment named practice, install nothing yet, and confirm it activates. Then open VS Code, create a file called hello.py with two expressions and two statements, and run it. Finally, fix the PATH if any command is not recognised before moving to Chapter 2.