Create A Simple Rule-Based Expert System.
Create A Simple Rule-Based Expert System.
A rule-based expert system is a computer program that uses a knowledge base of rules to make
decisions or solve problems. These systems are particularly useful for tasks that require human
expertise, such as medical diagnosis, financial analysis, or troubleshooting technical issues.
1. Knowledge Base: This stores facts and rules about the domain.
2. Inference Engine: This uses the rules to reason over the facts and derive new conclusions.
A Simple Example: A Car Diagnosis Expert System
Knowledge Base:
● Facts:
○ Car doesn't start.
○ Engine turns over slowly.
○ Battery light is on.
● Rules:
○ IF car doesn't start AND engine turns over slowly THEN possible cause is weak battery.
○ IF car doesn't start AND battery light is on THEN possible cause is weak battery.
Inference Engine:
Python
def expert_system(facts):
rules = [
("car doesn't start" and "engine turns over slowly", "weak
battery"),
("car doesn't start" and "battery light is on", "weak
battery")
]
while True:
new_facts = []
for fact, conclusion in rules:
if all(f in facts for f in fact):
new_facts.append(conclusion)
if not new_facts:
break
facts.extend(new_facts)
return facts
# Example usage:
facts = ["car doesn't start", "engine turns over slowly"]
diagnosis = expert_system(facts)
print(diagnosis) # Output: ['weak battery']
● Limited Knowledge Base: It can only handle a few simple rules and facts.
● No Uncertainty Handling: It doesn't account for uncertainty in the information.
● Lack of Explanation: It doesn't provide explanations for its conclusions.
To create a more robust expert system, consider: