ARTIFICIAL INTELLIGENCE · 2026

Programming in Artificial Intelligence

From core concepts to neural networks, NLP, and real-world AI systems — with live, runnable Python examples directly in the browser. Master AI programming with hands-on tutorials.

⏱ 25 min read 📅 Mar 2026 🎓 Intermediate 🤖 AI/ML

Advertisement

⏳ Loading Python runtime… please wait

01 — AI FUNDAMENTALS

What Is Artificial Intelligence?

Artificial Intelligence (AI) is the field of computer science focused on building systems that can perform tasks that typically require human intelligence — reasoning, learning, perception, language understanding, and decision-making. Modern AI is largely data-driven: systems learn patterns from examples rather than being explicitly programmed with rules. Python is the dominant language of AI because of its readability, rich ecosystem, and overwhelming adoption in research and industry.

AI is a broad field with several distinct subfields, each addressing a different class of problem:

Python · AI Concept Explorer runnable

Advertisement

02 — PYTHON & NUMPY FOUNDATION

The Numerical Foundation of AI

NumPy provides fast, vectorised N-dimensional arrays backed by optimised C code. Every major ML library — PyTorch, TensorFlow, Scikit-learn — operates on NumPy-compatible arrays internally. Vectorised operations avoid slow Python loops, running at near-C speed. Arrays support broadcasting, slicing, reshaping, and full linear algebra operations natively, making them the universal currency of numerical AI computation.

Python · NumPy Array Operations runnable

03 — DATA PREPROCESSING

Preparing Data for AI Models

Raw data is almost never ready for a machine learning model. Preprocessing transforms messy, inconsistent input data into a clean, structured format that a model can learn from effectively. The quality of preprocessing directly determines the quality of the model — a well-preprocessed simple model consistently outperforms a complex model fed raw, unclean data. Core steps include handling missing values, encoding categorical variables, scaling numerical features, and splitting data into training and test sets.

Python · Preprocessing Pipeline runnable

04 — LINEAR REGRESSION

The Fundamental ML Algorithm

Linear regression is the simplest and most fundamental ML algorithm. It models the relationship between input features and a continuous output as a straight line (or hyperplane in higher dimensions). The model finds the weights that minimise the Mean Squared Error between predictions and true values, either by solving the closed-form normal equation or iteratively via gradient descent.

Python · Linear Regression from Scratch runnable

05 — K-NEAREST NEIGHBOURS

Instance-Based Learning

K-Nearest Neighbours (KNN) is a simple, non-parametric classifier that stores all training instances and predicts labels based on the majority class of the k closest points in feature space. It's particularly useful for multi-class problems and when decision boundaries are irregular.

Python · KNN Classifier runnable

06 — NEURAL NETWORKS FROM SCRATCH

Building the XOR Network

A neural network consists of layers of neurons, each computing a weighted sum of its inputs followed by a non-linear activation function. The network learns by adjusting its weights through backpropagation — computing the gradient of a loss function with respect to each weight, then taking a small step in the direction that reduces the loss. This XOR example demonstrates how a simple network solves a non-linearly separable problem.

Python · Neural Network from Scratch runnable

07 — NATURAL LANGUAGE PROCESSING

TF-IDF Text Representation

Before any model can process text, it must be converted into numerical form. This pipeline involves tokenisation, building a vocabulary, and representing documents as vectors — either using bag-of-words, TF-IDF, or modern contextual embeddings. TF-IDF (Term Frequency-Inverse Document Frequency) weights words by their importance in a document relative to the whole corpus.

Python · TF-IDF Vectoriser runnable

08 — CLUSTERING (K-MEANS)

Unsupervised Learning

Unsupervised learning finds hidden structure in data without any labelled examples. K-Means clustering partitions data into K groups by iteratively assigning points to the nearest centroid and recomputing centroids until convergence. Applications include customer segmentation, document grouping, and anomaly detection.

Python · K-Means from Scratch runnable

09 — MODEL EVALUATION

Measuring Performance

Accuracy is intuitive but misleading on imbalanced datasets. Precision measures the fraction of positive predictions that are actually positive. Recall measures the fraction of actual positives that were detected. The F1 score balances both. ROC-AUC measures the model's ability to discriminate between classes across all thresholds.

Python · Evaluation Metrics runnable

10 — GENERATIVE AI & ETHICS

Language Models and Responsible AI

Language models learn to predict the next token in a sequence given all preceding tokens. Through this simple objective applied to enormous text corpora, they develop the ability to reason, summarise, translate, and answer questions. Building AI responsibly requires understanding Fairness (audit for bias), Transparency (document limitations), Privacy (protect sensitive data), and Robustness (test edge cases).

Python · Bias Detection runnable

Advertisement

Share this guide:

DISCUSSION

Comments & Feedback

This is a demo comment section using browser storage. To connect a real backend, replace with your own service.

FAQ

Frequently Asked Questions

AI is the broad field of making machines intelligent. Machine learning is a subset of AI where systems learn from data. Deep learning is a subset of ML using multi-layer neural networks. All deep learning is ML, and all ML is AI, but not vice versa.

Python dominates AI due to its readability, extensive ecosystem (NumPy, PyTorch, TensorFlow, scikit-learn), strong community, and seamless integration with C/C++ for performance-critical operations. Its simplicity lets researchers focus on algorithms rather than language complexities.

Pyodide is a Python distribution for WebAssembly that runs entirely in the browser. It compiles CPython to WebAssembly, enabling Python code execution without a server. It includes scientific libraries like NumPy, making it perfect for interactive AI tutorials.

All code samples above run entirely in your browser using the Pyodide Python runtime — no server, no installation required. You can edit any code block and click Run to see your changes immediately.

Stay in the Loop

Get new guides, code deep-dives, and Python insights delivered to your inbox.

No spam Free forever Unsubscribe anytime

Join readers learning Python & AI.

Artificial Intelligence Programming — By: Glenn Junsay Pansensoy | domain: code-sense.pansensoyglenn.workers.dev | updated: 2026-03-01