This project involves building and training a multilayer neural network capable of classifying animals into one of seven types based on their characteristics. The neural network is trained using data from the zoo.txt
file, which contains details about 121 animals, each described by 18 attributes. The primary goal is to adapt existing code for neural network training to solve this classification problem.
- Learn to adapt and extend neural network training code for a new classification problem.
- Implement functions to process data and generate training and test sets.
- Train a neural network to correctly identify animal types.
- Evaluate the performance of the trained neural network.
- Neural network with backpropagation for training.
- Conversion of animal data into structured training patterns.
- Support for 7 animal types as outputs.
- Evaluation and accuracy calculation for test datasets.
The dataset is split into:
- Input Attributes: 16 numerical attributes (e.g., feathers, milk production, etc.).
- Animal Type: The final classification output with 7 possible types (e.g., mammal, reptile).
Each line in zoo.txt
describes an animal:
- The first value is the animal's name.
- The next 16 values are numerical inputs.
- The last value is the animal type.
This function processes the dataset and creates:
- Training Set: First 67 patterns.
- Test Set: Remaining patterns.
Steps:
- Read and parse each line from
zoo.txt
. - Convert attributes into binary input patterns.
- Generate output patterns based on animal types.
- Randomize the order of patterns.
Converts individual animal data into a structured pattern:
- Input:
[name, attributes, type]
- Output:
[animal_name, input_pattern, animal_type, output_pattern]
Example:
Input: ["aardvark", 1, 0, 0, 1, ..., "mammal"]
Output:
['aardvark', [1, 0, 0, 1, 0, ..., 1], 'mammal', [1, 0, 0, 0, 0, 0, 0]]
-
Trains the neural network for 300 iterations using the training set.
-
Calls the iterate function to adjust weights for each training pattern.
-
Tests the trained network using the test set.
-
Outputs predictions and compares them with actual types.
-
Calculates and prints the success rate.
-
Example output:
The network thinks mongoose is a mammal, it should be a mammal
Success rate: 94.12%
- Converts neural network outputs into corresponding animal types.
-
Analyze and understand the provided code for Boolean functions (AND, OR, XOR).
-
Implement the
build_sets
andtranslate
functions to prepare training and test datasets. -
Train the neural network using the
train_zoo
function. -
Test the neural network using the
test_zoo
function and evaluate performance.
-
Accuracy: Percentage of correct classifications.
-
Output Comparison: Detailed predictions for each test case.
-
Example input: Attributes of an animal (binary format).
-
Predicted output:
['mammal', 'reptile', ...]
. -
Success rate: e.g.,
94.12%
.
-
Python: Ensure Python is installed on your system.
-
Required libraries: NumPy (or other dependencies mentioned in the provided code).
-
Place the zoo.txt and info.txt files in the project directory.
-
Run the script to process data and train the network.
-
Use the test function to evaluate network performance.
Course Material: Artificial Intelligence
Provided by: Mr. Arlindo Silva
Files: zoo.txt, info.txt, and sample neural network training code.
Aziz Zina and Rafik Baaziz.