AI  

Part3 - The Shift to Machine Learning

image_2026-07-16_112012317

Part 3 explains the move from explicit rules to models that learn useful patterns from examples.

Introduction

In the previous parts [Part1, Part2], we built the foundation: AI is not a magic brain, and modern AI systems are not simply large collections of if-else statements. They work because they learn patterns from examples.

This part focuses on one of the most important shifts in software engineering: moving from rule-based systems to machine learning systems.

For developers, this shift changes how we think about logic, data, errors, testing, and deployment. In traditional software, we write the rules. In machine learning, we design the learning process and let the model discover useful rules from data.

From Rules to Learning

Traditional software is deterministic. If the same input goes through the same code path, the output is usually the same. The developer writes the logic, handles the edge cases, and controls the behavior directly.

That works beautifully when the problem is clear. For example, tax calculation, invoice totals, permissions, validations, and workflow rules are perfect examples of rule-based software.

But many real-world problems are messy. A cat can have triangular ears, but so can a fox. A dog may have whiskers. A message may look like spam but still be legitimate. A house price may depend on dozens of invisible market signals.

When exceptions become too many, writing every rule by hand becomes fragile. Machine learning gives us another approach: provide examples, define the goal, and train a model to learn patterns.

image_2026-07-16_112027397

Rule-based systems depend on explicit logic. Machine learning systems learn useful behavior from examples.

What Is a Model?

A machine learning model is a learned mathematical function. It is not conscious, and it does not understand the world like a human. It maps inputs to outputs using patterns learned from data.

A simple way to think about it is this:

output = model(input)

For a house-price model, the input may include size, location, bedrooms, roof age, school quality, and market conditions. The output is the predicted price.

The real world does not give us a perfect formula for house prices. There are too many factors: buyer psychology, market timing, nearby development, school demand, interest rates, and more. The model tries to approximate that unknown real-world function.

image_2026-07-16_112044286

A model approximates an unknown real-world function by learning from data.

A Simple Formula View

A very simple model can be written as a line:

y = m*x + b

Here, x is the input, y is the output, m is the weight or slope, and b is the bias. In a house-price example, a simplified formula may look like this:

price = (size w1) + (bedrooms w2) + bias

Real machine learning models can contain millions or billions of learned numbers, but the basic idea is the same. Training adjusts weights and bias so the prediction becomes closer to reality.

When developers share a trained model file such as .pt, .h5, .onnx, or .bin, that file usually contains these learned numbers. The intelligence is stored as mathematics.

Features and Vectors

Machine learning models do not directly understand houses, images, text, or audio. They understand numbers. So before a model can learn, real-world information must be converted into numerical form.

A feature is a measurable property. For a house, features might include square footage, year built, number of bathrooms, neighborhood score, or distance from the city center.

Square footage = 2500

Year built = 1900

Bathrooms = 3

Feature vector = [2500, 1900, 3]

A vector is simply a list of numbers. Once information becomes a vector, mathematics becomes possible: distance, similarity, grouping, ranking, classification, and prediction.

image_2026-07-16_112104521

Feature extraction turns real-world information into numbers a model can learn from.

Images, Text, and Embeddings

The same idea applies to images and text. An image is a grid of pixels. Each pixel can be represented by RGB values, usually from 0 to 255. A 1000 x 1000 image has about one million pixel positions.

Text is also converted into numerical form. Modern AI systems use embeddings, which represent words, sentences, or documents as vectors of meaning.

A famous embedding example is:

vector("king") - vector("man") + vector("woman") ~= vector("queen")

This does not mean the model understands royalty like a human. It means relationships between concepts can be represented as positions and directions in vector space.

image_2026-07-16_112116762

Embeddings help AI systems represent meaning, similarity, and relationships mathematically.

Supervised Learning: Learning With Labels

Supervised learning means the model is trained with labeled examples. The input is provided along with the correct answer.

Email: "Buy cheap medicine now" -> Spam

Email: "Meeting at 5 PM" -> Not spam

The model makes a prediction, compares it with the real label, calculates loss, and updates itself to reduce future mistakes.

This is common in spam detection, image classification, disease prediction, credit scoring, and many business forecasting systems.

Supervised learning is powerful, but labels are expensive. Someone has to prepare the correct answers, and bad labels can teach the model bad behavior.

image_2026-07-16_112133428

Machine learning can use labels, hidden patterns, or rewards depending on the problem.

Classification and Regression

In classification, the model predicts a category. Examples include spam or not spam, cat or dog, malignant or benign, approved or rejected.

In regression, the model predicts a continuous number. Examples include house price, tomorrow's temperature, expected revenue, or delivery time.

This distinction matters because it changes how we measure success. Classification often uses accuracy, precision, recall, or F1 score. Regression often uses error measurements such as MAE or RMSE.

Loss: The Model's Error Signal

Loss is the difference between the model's prediction and the correct answer. During training, the model tries to minimize loss.

prediction = model(input)

loss = difference between prediction and real label

training goal = minimize loss

If the model predicts the correct label, loss is low. If the prediction is far from the real answer, loss is high. Training is basically a long process of reducing this error.

image_2026-07-16_112151401

Training repeatedly measures error and updates weights to reduce future mistakes.

Unsupervised Learning: Finding Hidden Patterns

Unsupervised learning works without labels. The model receives raw data and tries to discover structure.

For example, a retailer may analyze purchases and discover customer clusters. One group may buy suits, ties, and watches. Another may buy diapers, formula, and wet wipes. The computer does not know the names of those groups; it only finds that some behaviors are close together.

This is useful for customer segmentation, recommendation systems, anomaly detection, and fraud monitoring.

In fraud detection, normal transactions may form a dense cluster. A sudden foreign high-value transaction may appear far away from the usual pattern, so the system flags it for review.

Reinforcement Learning: Learning Through Rewards

Reinforcement learning is different from learning from a static dataset. An agent takes actions in an environment and receives rewards or penalties.

Move forward: +1 reward

Fall down: -100 penalty

A robot learning to walk is a good example. Instead of writing exact rules like 'move the left leg 45 degrees', we define rewards and let the agent learn through repeated trials.

This works well in simulations, games, robotics research, and agent-based systems. It is powerful, but it also needs careful reward design and safe environments for experimentation.

Training vs. Inference

Training is the learning phase. The model looks at examples, makes predictions, calculates loss, and updates weights.

Inference is the usage phase. The model is already trained, and now we send new input to get an output.

image_2026-07-16_112203851

Training teaches the model. Inference uses the trained model in an application.

Training is usually expensive because it needs large datasets, GPUs or TPUs, memory, electricity, and time. Inference is usually faster per request, but at scale it can still become expensive.

A simple business analogy: training is building the factory; inference is running the factory.

Transfer Learning and Fine-Tuning

Most teams do not train a foundation model from zero. Instead, they start with a pretrained model that already learned broad patterns from large datasets.

Fine-tuning means taking that existing model and training it a little more on specific domain data. For example, a general language model can be fine-tuned on legal, medical, support, or internal company documents.

This is why modern AI development often feels different from traditional ML research. Developers usually integrate, adapt, evaluate, and monitor models rather than training everything from scratch.

Why This Matters for Software Engineers

Machine learning changes the developer's job from writing every rule to designing a reliable learning system.

  • Choose the right data and avoid noisy or biased examples.

  • Convert real-world inputs into useful features or embeddings.

  • Understand whether the task is classification, regression, clustering, or reinforcement learning.

  • Measure performance with the right metrics instead of trusting impressive demos.

  • Separate training concerns from inference concerns in architecture and cost planning.

  • Monitor production behavior because data can drift over time.

The key point is simple: machine learning is still engineering. It has inputs, outputs, trade-offs, failure modes, tests, infrastructure, and maintenance.

Conclusion

The shift to machine learning is the shift from explicitly coded rules to learned patterns. Instead of trying to manually describe every exception, we use data to teach models how to approximate useful behavior.

Models are mathematical functions. Features and vectors are the bridge between the real world and math. Training reduces loss by adjusting weights. Inference uses the trained model in real applications.

Once software engineers understand this foundation, AI becomes easier to reason about, design, debug, and deploy.

In the next part of this series, we will move into the neural revolution: perceptrons, neural networks, deep learning, generative AI, large language models, tokens, hallucinations, and RAG.