Everyday Guidebooks
Cover of Build Your First Rule-Based AI

Business, AI & Entrepreneurship

Build Your First Rule-Based AI

A Beginner's Guide to Rules, Decisions, and Testing with a Simple Meal Selector

by Todd Michael

Available now

Searching for how to make an ai for beginners without getting lost in complicated math or expensive tools? Start with a small program that makes a decision you can follow: choosing a meal from a few stated preferences.

In Build Your First Rule-Based AI, Todd Michael guides you through creating a Python meal selector one understandable step at a time. You'll collect and check inputs, write rules, trace the path to a recommendation, and test what happens when preferences conflict. Along the way, you'll learn how to explain a result, catch mistakes, and make thoughtful improvements without pretending your program can learn from data.

No prior programming experience is assumed. The book introduces the Python essentials needed for the project and includes worked examples, exercises, and checks for your results. By the final chapter, you'll have a working rule-based program and a clearer understanding of how it differs from machine learning.

Contents
  1. 1. Meet Your Meal-Choosing Program
  2. 2. Set Up a Place to Code
  3. 3. The Python Essentials
  4. 4. From Preferences to a Decision Table
  5. 5. Write Your First Rules
  6. 6. Collect and Check Inputs
  7. 7. Trace the Decision
  8. 8. When Preferences Conflict
  9. 9. Build a Useful Test Set
  10. 10. Debug and Repair Your Rules
  11. 11. Organize the Program
  12. 12. Add a Careful Improvement
  13. Choose One Improvement
  14. Update the Decision Table First
  15. Decide What Happens in a Conflict
  16. Add and Validate the Input
  17. Apply the Preference to Every Candidate
  18. Keep the Explanation Honest
  19. Expand the Test Set
  20. Trace One New Case
  21. Review the Change as a Whole
  22. 13. Rules and Machine Learning
  23. 14. Finish, Review, and Share
  24. Other Books by Todd Michael

Read a sample: 1. Meet Your Meal-Choosing Program

It is nearly time to eat, and you have a familiar problem: you know a few things about what you want, but you do not know what to make.

Perhaps you want a vegetarian meal. Perhaps you have limited time. Perhaps you would rather not eat rice again. A friend could listen to those preferences, consider a few possibilities, and suggest dinner. A small computer program can do something similar—provided we tell it what choices it can consider and how to decide among them.

In this book, you will build that program. It will ask for a few preferences, follow rules that you write, and recommend a meal when its small menu contains a suitable choice. When the stated requirements cannot be met by any supported meal, it will say so instead of pretending otherwise.

The finished project will be modest. It will not inspect your refrigerator, browse restaurant menus, or invent recipes. It will not know what you enjoyed yesterday unless you supply that information and add rules for using it. Its value is that you can see how a decision is made, test whether the decision fits the rules, and improve those rules when they fall short.

That makes the meal selector a useful first step into rule-based artificial intelligence. You do not need to understand Python, programming, or AI terminology before starting. We will build the ideas gradually, beginning with the decision itself.

Imagine a version of the finished program offering three meals:

- Bean tacos - Vegetable stir-fry with rice - Chicken and rice

For this preview, suppose the program knows a few simple facts about those choices. Bean tacos and vegetable stir-fry are vegetarian; chicken and rice is not. The tacos and chicken and rice are marked as quick options, while the stir-fry is not. Both rice dishes contain rice; the tacos do not.

These are labels for our hypothetical menu, not claims about every possible recipe. Actual preparation time and ingredients depend on how a meal is made. Later, we will choose and document a fixed set of meals and attributes for the version we build.

A conversation with the selector might look like this:

> Program: Do you require a vegetarian meal? > You: Yes > Program: Do you require a quick meal? > You: Yes > Program: Would you prefer to avoid rice? > You: Yes > Program: Recommendation: Bean tacos > Program: Why: They meet your vegetarian and quick-meal requirements and match your preference to avoid rice.

The program has not tasted the tacos or judged them delicious. It has compared the answers with the information and rules available to it. In this example, bean tacos satisfy both requirements and also fit the stated preference.

Notice the difference between a requirement and a preference. A requirement is a condition the recommendation must meet. A preference is something the user would like when possible, but which the program may treat as flexible. The program should make that distinction clear rather than quietly deciding that a requirement no longer matters.

For instance, imagine the user requires a vegetarian meal, requires a quick meal, and says rice is fine. Under our preview labels, bean tacos still qualify. But if none of the supported meals met both requirements, the appropriate response would be a no-match message—not a recommendation that ignores one of the answers.

A no-match result is still a result. It tells the user something useful about the program’s limited menu: given the stated conditions and the information available, this selector has no suitable recommendation to offer.

A rule is an instruction that connects a condition to an action. In everyday language, it often has this shape:

> If a condition is true, do something.

You use rules like this without thinking much about them. If rain is expected, take an umbrella. If the library is closed, return the book tomorrow. A meal selector can use the same basic structure:

> If the user requires a vegetarian meal, consider only supported meals marked vegetarian.

Another rule might say:

> If more than one eligible meal remains and the user prefers to avoid rice, favor an eligible meal marked as containing no rice.

The second rule matters because it does not turn a preference into a requirement. It helps choose among meals that have already met the requirements. If avoiding rice is only a preference, the selector may still suggest an eligible rice dish when no eligible rice-free dish is available. Its explanation should make that trade-off visible.

A collection of rules, together with the information those rules use, forms a rule-based system. The system receives information, checks conditions, and produces an outcome according to explicitly stated instructions.

The word explicitly is important. A human might say, “Pick something that sounds good,” and expect another person to fill in the gaps. A computer program needs a more precise account of what information to check and what to do with it. “Sounds good” could mean quick, familiar, inexpensive, spicy, or simply appealing at that moment. Unless we define a way to represent and use one of those ideas, the program cannot reliably act on it.

Precision does not require complicated language. A clear rule can be short. The challenge is making sure that all the short rules work together.

Let us look more closely at the first conversation. The answers were:

- Vegetarian required: yes -…

More Business, AI & Entrepreneurship

Cover of AIAIAvailable nowCover of The New Gold RushThe New Gold RushAvailable nowCover of Leadership Intelligence for Succession PlanningLeadership Intelligence for Succession PlanningAvailable nowCover of Remote Jobs and the Scam TestRemote Jobs and the Scam TestAvailable nowCover of The Entrepreneur Mindset for Patient DecisionsThe Entrepreneur Mindset for Patient DecisionsAvailable nowCover of Price Without ApologyPrice Without ApologyAvailable now

About Todd Michael

Todd Michael is an American author and the founder of ToddMichael.tv. He writes practical, plain-English books on money, health, preparedness, technology, games, humor and more.

About the author Todd Michael · Todd Michael’s author site

Part of the ToddMichael.tv network.