Weather Expert System Documentation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Weather Expert System Documentation

Expert System
G1
Dr. Ayman Soliman
Eng. Mohamed Ibrahem

Mohamed Saleh 42021256


Khaled Amr 42021257
Mostafa Yasser 42020159
Weather Expert System Documentation
Overview

The Weather Expert System is a Python program designed to predict weather conditions based
on user-provided inputs such as temperature, humidity, and wind speed. It utilizes a rule-based
approach with a knowledge base and an inference engine to make predictions. This
documentation provides an in-depth understanding of the system's architecture, functionality,
usage, and extensibility.

Architecture

the Weather Expert System consists of the following main components:

1. Rule-Based Knowledge Base: Contains a collection of rules that map specific


combinations of input factors (e.g., temperature, humidity, wind speed) to predicted
weather conditions.
2. Inference Engine: Evaluates the rules in the knowledge base based on user inputs and
selects the most appropriate prediction.
3. User Interface: Interacts with the user to gather input data and display the predicted
weather condition.

Classes

1. Rule Class

The Rule class represents a rule in the knowledge base. Each rule consists of a condition and a
result.

• Attributes:
o condition: A dictionary representing the condition of the rule. Keys are input
factors (e.g., temperature, humidity), and values are their corresponding states
(e.g., hot, cold).
o result: A string representing the predicted weather condition if the rule's
condition is met.
• Methods:
o evaluate(inputs): Evaluates whether the given inputs satisfy the rule's
condition.

2. ExpertSystem Class
The ExpertSystem class serves as the inference engine. It manages a collection of rules and
provides methods to add rules and predict weather conditions.

• Attributes:
o rules: A list storing instances of Rule representing the knowledge base.
• Methods:
o add_rule(condition, result): Adds a new rule to the knowledge base.
o predict(inputs): Predicts the weather condition based on the provided
inputs by evaluating the rules.

Usage

1. Initialization:
o Create an instance of the ExpertSystem class to initialize the expert system.
2. Adding Rules:
o Use the add_rule(condition, result) method to add rules to the knowledge
base. Each rule defines conditions based on input factors and their states.
3. Gathering Inputs:
o Prompt the user to input values for temperature, humidity, and wind speed.
4. Making Predictions:
o Convert the user inputs into a format suitable for inference.
o Use the predict(inputs) method of the ExpertSystem instance to predict the
weather condition based on the provided inputs.

Example
python
# Initialize the expert system
expert_system = ExpertSystem()

# Define rules for the expert system


expert_system.add_rule({"temperature": "hot", "humidity": "high",
"wind_speed": "low"}, "It's likely to be warm and humid with light winds.")
expert_system.add_rule({"temperature": "cold", "humidity": "low"}, "It's
likely to be cold and dry.")
expert_system.add_rule({"wind_speed": "high"}, "It's likely to be windy.")

# Gather user inputs


inputs = {"temperature": "hot", "humidity": "high", "wind_speed": "low"}

# Predict the weather


prediction = expert_system.predict(inputs)

# Output the prediction


print("Based on the inputs provided, the predicted weather is:", prediction)

Extensibility
• Adding Rules: Additional rules can be added to the knowledge base to enhance the
system's accuracy and coverage. Consider incorporating more complex conditions and
refining existing rules based on domain expertise or empirical data.
• Incorporating External Data: The system can be extended to incorporate real-time
weather data from external sources, enabling more accurate predictions based on
current weather conditions.
• Improving User Interface: Enhance the user interface to provide a more intuitive and
informative experience, such as graphical representations of predicted weather patterns
or interactive feedback.

Notes

• This expert system provides a simplistic approach to weather prediction and may not
cover all possible scenarios.
• Continuous refinement and expansion of the knowledge base and inference engine are
essential for improving prediction accuracy and robustness.

You might also like