Machine Learning with LLMs in VBA
Introduction to Machine Learning
What Is Machine Learning?
Think about how you'd teach a child to recognize a dog. You wouldn't write a long list of rules like "if it has four legs, fur, and a tail, it's a dog." A cat fits that description, and so do other animals. Instead, you'd show the child pictures of dogs—big dogs, small dogs, fluffy dogs, short-haired dogs—and say, "This is a dog."
Eventually, the child's brain figures out the underlying patterns on its own. Machine learning (ML) works in a similar way. It's a field of artificial intelligence where computers learn to find patterns and make decisions from data, rather than being explicitly programmed with a set of rules for every possible situation.
This ability to learn from experience is what makes machine learning so powerful. It's the engine behind spam filters that adapt to new junk mail, recommendation systems that know what movie you'll want to watch next, and medical tools that can spot diseases in scans. Instead of writing code to solve a problem, we let the machine build its own solution by learning from examples.
Three Ways Machines Learn
Just as people have different learning styles, machines can learn in a few distinct ways. The method you choose depends on the problem you're trying to solve and the kind of data you have.
Supervised learning is like studying with a teacher who provides both the questions and the correct answers.
In supervised learning, the machine is trained on a dataset that is fully labeled. Each piece of data has a known outcome or answer. For example, to build a spam filter, you'd feed the model thousands of emails, each one already marked as either "spam" or "not spam." The model's job is to learn the relationship between the content of an email and its label, so it can later classify new, unseen emails correctly.
label
noun
The correct answer or outcome for a piece of data in a supervised learning task.
Unsupervised learning is the opposite. The machine is given data with no labels and must find patterns or structures on its own. Imagine dumping a huge box of mixed Lego bricks on the floor and asking a computer to sort them. It might group them by color, by shape, or by size. It's discovering the inherent structure without any prior guidance. This is useful for tasks like grouping customers with similar buying habits or identifying unusual activity in a computer network.
Finally, there's reinforcement learning. This approach is all about trial and error. The machine, often called an "agent," learns by performing actions in an environment to achieve a goal. It receives rewards for actions that get it closer to the goal and penalties for actions that don't. Think of training a pet. A correct action gets a treat (a reward). Over time, the agent learns a strategy, or "policy," that maximizes its total reward. This is the technique used to train computers to play complex games like Go or to control robotic arms.
The Machine Learning Workflow
Regardless of the learning type, developing a machine learning model generally follows a standard process. It's an iterative cycle of gathering data, preparing it, and using it to train and improve the model.
Here's a breakdown of the steps:
-
Data Collection: First, you need data. This could be anything from spreadsheets of customer information to a library of images or text from websites.
-
Data Preparation: Raw data is often messy. This step involves cleaning the data (like removing errors or filling in missing values) and formatting it in a way the model can understand. This is often the most time-consuming part of the process.
-
Model Training: This is where the learning happens. You select an appropriate algorithm and feed your prepared data into it. The algorithm adjusts its internal parameters to find patterns in the data.
-
Model Evaluation: Once the model is trained, you need to check how well it performs. This is done by testing it on a separate set of data it has never seen before. This tells you if the model can generalize its learning to new situations.
-
Deployment: If the model's performance is good enough, it's put into a real-world application. The process doesn't stop here, though. Models are continuously monitored and often retrained with new data to keep them accurate and relevant.
What is the primary difference between machine learning and traditional programming?
You are tasked with building a system to predict whether a credit card transaction is fraudulent. You have a historical dataset where each transaction is already marked as 'fraudulent' or 'legitimate'. Which type of machine learning is most appropriate?
Understanding these core concepts—what machine learning is, its main types, and the general workflow—provides the foundation for exploring how this technology is used to solve countless real-world problems.

