This script employs a Genetic Algorithm-based Neural Network and Holographic Reduced Representation (HRR) to classify wine types based on the UCI ML Wine recognition dataset. The Neural Network is implemented using the Keras library.
This script uses the following Python libraries:
- numpy
- keras
- sklearn
- random
You can install them using pip
:
pip install numpy keras sklearn
Simply run the Python script in a suitable Python environment:
python main.py
The script will also load an existing model and HRR weights, if available, for inmediate use. If you wish to train a new model, simply delete the existing files.
This script consists of several steps:
-
Loading the wine dataset: The UCI ML Wine recognition dataset is loaded using the
sklearn.datasets.load_wine
function. -
Data Preprocessing: The loaded dataset is split into training and testing datasets. The features are then standardized using the
StandardScaler
class fromsklearn.preprocessing
. -
Holographic Reduced Representation (HRR) Encoding: A function
encode_hrr
is provided to apply HRR encoding to the features. -
Genetic Algorithm: This algorithm includes creating individuals, initializing the population, defining the fitness function, performing selection, crossover, and mutation operations.
-
Prediction: The trained model predicts the wine class based on user input.
- Model: The best individual model is saved as 'model.h5'.
- Model Weights: The weights of the best individual model are saved as 'model_weights.h5'.
- HRR Weights: The HRR weights of the best individual are saved as 'hrr_weights.npy'.
- Accuracy Score: The final accuracy score of the best individual on the test set is printed to the console.
- Confusion Matrix and Classification Report: The confusion matrix and the classification report are also printed to the console, providing detailed insights into the performance of the model.
This script is based on the UCI ML Wine recognition dataset.