import streamlit as st
def main():
st.set_page_config(page_title="Genetic Algorithm for Feature Selection", layout="wide")
st.title("Genetic Algorithm for Feature Selection")
# Introduction and Description
st.header("Genetic Algorithm")
st.markdown("""
The Genetic Algorithm (GA) is an evolutionary algorithm (EA) inspired by Charles Darwin’s theory of natural selection which espouses Survival of the fittest. As per the natural selection theory, the fittest individuals are selected to produce offsprings. The fittest parents' characteristics are then passed on to their offsprings using cross-over and mutation to ensure better chances of survival. Genetic algorithms are randomized search algorithms that generate high-quality optimization solutions by imitating the biologically inspired natural selection process such as selection, cross-over, and mutation.
""", unsafe_allow_html=True)
# Terminology
st.header("Terminology for Genetic Algorithm")
st.image("Terminology for Genetic Algorithm.png")
st.markdown("""
- **Population**: A set of possible solutions for the stochastic search process to begin. GA iterates over multiple generations till it finds an acceptable and optimized solution. The first generation is randomly generated.
- **Chromosome**: Represents one candidate solution present in the generation or population, also referred to as a Genotype. A chromosome is composed of Genes that contain the value for the optimal variables.
- **Phenotype**: The decoded parameter list for the genotype that is processed by the Genetic Algorithm. Mapping is applied to the genotype to convert to a phenotype.
- **Fitness Function**: Or the objective function evaluates the individual solution or phenotypes for every generation to identify the fittest members.
""", unsafe_allow_html=True)
# Genetic Operators
st.header("Different Genetic Operators")
st.markdown("""
- **Selection**: The process of selecting the fittest solution from a population. The fittest solutions act as parents for the next generation. Selection can be performed using Roulette Wheel Selection or Ranked Selection based on the fitness value.
""", unsafe_allow_html=True)
st.markdown("""
- **Cross-over or Recombination**: Happens when genes from the two fittest parents are randomly exchanged to form a new genotype or solution. Cross over can be a One-point cross over or Multi-Point Cross over based on the parent's segments of genes exchanged.
""", unsafe_allow_html=True)
st.image("Cross-over.png")
st.markdown("""
- **Mutation**: After a new population is created through selection and crossover, it is randomly modified through mutation to promote diversity in the population to find better and optimized solutions.
""", unsafe_allow_html=True)
st.image("Mutation.png")
# Usage in AI
st.header("Usage of Genetic Algorithm in Artificial Intelligence")
st.markdown("""
A Genetic Algorithm is used for Search and Optimization using an iterative process to arrive at the best solution out of multiple solutions. For instance:
1. Finding an appropriate set of hyperparameters for a deep learning model to increase its performance.
2. Determining the best amount of features to include in a machine learning model for predicting the target variable.
""", unsafe_allow_html=True)
# Working of Genetic Algorithm
st.header("Working of Genetic Algorithm")
st.image("Working of Genetic Algorithm.png")
# Implementation
st.header("Implementation of Genetic Algorithm for Feature Selection")
st.markdown("""
The implementation involves several steps:
1. Initializing a random population.
2. Running the population through a fitness function to return the best parents (highest accuracy).
3. Selection from these best parents will occur depending on the n-parent parameter.
4. These parents are then put through the crossover and mutation functions respectively.
5. A new generation is created by selecting the fittest parents from the previous generation and applying cross-over and mutation.
6. This process is repeated for a specified number of generations.
""", unsafe_allow_html=True)
# Add a footer
st.markdown("---")
st.write("Made with ❤️ by Viga, Hanum, & Robit")
if __name__ == "__main__":
main()