AI & Machine Learning Topic

Python for AI and Data Science: A Simple First Project

You do not need to build a chatbot on your first day. Start with a small question: how many people visited a lesson, and is any data missing? You can answer it with a few lines of Python.

Artificial intelligence, or AI, is a broad field of computer systems that do tasks such as recognising images or generating text. Machine learning, or ML, is one approach: software learns patterns from examples. Deep learning uses neural networks with many layers. These systems can make useful predictions, but they can also be wrong.

What you need first

Learn variables, lists, dictionaries, loops and functions. Practise reading an error message. You do not need advanced maths to begin this lesson. Use a separate environment so practice packages do not change another project's setup.

python3 -m venv .venv
source .venv/bin/activate
python -m pip install numpy pandas matplotlib

If your computer uses python3 instead of python, use that command. On Windows, activate the environment with .venv\Scripts\activate. Install a Python version supported by the packages. The downloadable examples include the versions checked for this course.

Four tools and their jobs

  • NumPy works with arrays of numbers and many mathematical operations.
  • pandas works with rows and columns, similar to a spreadsheet.
  • Matplotlib draws charts.
  • JupyterLab lets you work in notebook cells with code, notes and results together.

A notebook is optional. You can learn the same ideas in a normal Python file. To try notebooks later, install jupyterlab in the environment and run jupyter lab.

A complete local example

Save this as python_data.py. The visit counts are invented. One row has a missing value.

from pathlib import Path
import numpy as np
import pandas as pd
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

frame = pd.DataFrame({"day": [1, 2, 3, 4], "visits": [10, 12, None, 18]})
print("Missing visits:", frame["visits"].isna().sum())
observed = frame.dropna(subset=["visits"])
print("Observed mean:", np.mean(observed["visits"].to_numpy()))
fig, ax = plt.subplots()
ax.plot(observed["day"], observed["visits"], marker="o")
ax.set(xlabel="Day", ylabel="Observed visits", title="Made-up lesson visits")
fig.savefig("lesson-visits.png", bbox_inches="tight")
plt.close(fig)
python python_data.py

The program should report one missing visit count and an observed mean of about 13.33. It saves lesson-visits.png in the current folder. The missing day is excluded, not silently replaced with zero. The line joins the observed points; it does not prove what happened on the missing day.

Read the code in small steps

A DataFrame holds the table. isna finds missing entries. dropna returns rows that have a value for visits. to_numpy gives NumPy the observed numbers. The chart has labels so another person knows what the axes mean.

We use a non-interactive chart backend so the file can also be created without a desktop window. Open the saved PNG to see the result. In a notebook, you could display the figure instead.

Good habits from the start

Keep the original data unchanged and record how you cleaned it. Check units, duplicates and missing values before fitting a model. Use clear names. Avoid private data in screenshots or shared notebooks. Restart a notebook and run all cells in order before sharing it; hidden earlier state can make results hard to repeat.

Try it yourself

Add day five with 20 visits. Predict whether the observed mean will rise, then run the program. Next, replace the missing value with zero in a copy. Explain why that changes the meaning of the data, not just the output.

Continue with simple maths for ML and data preparation. The goal is to understand each step before adding more tools.

Choose your next learning path

You do not need to finish every advanced maths topic before exploring a simple read-only AI app.

Official references

Reviewed on 25 October 2026. Use documentation for your installed versions.

All AI & Machine Learning tutorials

Comments (0)

No comments yet. Be the first to comment!

LecturreAI Assistant

Hello! I'm LecturreAI

What would you like to learn today?