mga-ckx / main.ipynb
main.ipynb
Raw
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mga import *\n",
    "from selection import *\n",
    "from ckx import *\n",
    "from mutation import *\n",
    "from problem import *\n",
    "from metrics import classification_metrics_kfold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = \"BreastCancer\" #Datasets: BreastCancer, diabetes, echocardiogram, hepatitis,\n",
    "                            #kidney_disease, Liver, parkinsons, SAheart, SPECT, SPECTF, \n",
    "                            #Vertebral, WDBC, WPBC\n",
    "\n",
    "dataset_name = f'{dataset}/{dataset}'\n",
    "route_dataset = \".\\\\data\\\\\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Progress: 5/10000, Fitness: 0.32338267321577635\n",
      "Progress: 11/10000, Fitness: 0.2719626684231862\n",
      "Progress: 1001/10000, Fitness: 0.22130821778552107\n",
      "Progress: 2003/10000, Fitness: 0.20950688366090123\n",
      "Progress: 3005/10000, Fitness: 0.203646154715376\n",
      "Progress: 4001/10000, Fitness: 0.20052424676616715\n",
      "Progress: 5001/10000, Fitness: 0.19910962225966494\n",
      "Progress: 6003/10000, Fitness: 0.19682924469006624\n",
      "Progress: 7003/10000, Fitness: 0.1942305617796493\n",
      "Progress: 8005/10000, Fitness: 0.19240061427416136\n",
      "Progress: 9001/10000, Fitness: 0.19138781398765872\n",
      "Progress: 10003/10000, Fitness: 0.19045059351052002\n"
     ]
    }
   ],
   "source": [
    "problem = ffnnKFold(route_dataset, dataset_name)\n",
    "\n",
    "algorithm = MicroGAFFNN(\n",
    "    problem=problem,\n",
    "    mutation=UniformMutation(0.01),\n",
    "    crossover=CrossKnowledgeCrossover(0.9),\n",
    "    selection=BinaryTournamentSelection(),\n",
    "    max_evaluations=10000,\n",
    "    freq = 1000,\n",
    ")\n",
    "\n",
    "algorithm.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "TRAIN:\n",
      "\n",
      "Accuracy: 0.7362358676485841\n",
      "Precision: 0.7300294562579375\n",
      "TN: 72.89999999999999 FP: 57.6 FN: 2.43 TP: 15.569999999999999\n",
      "Specifity: 0.5586206896551723\n",
      "Sensitivity: 0.865\n",
      "G-Mean: 0.6951308485110728\n",
      "\n",
      "TEST:\n",
      "\n",
      "Accuracy: 0.7365546218487394\n",
      "Precision: 0.73649252357948\n",
      "TN: 8.1 FP: 6.3999999999999995 FN: 2.7 TP: 17.3\n",
      "Specifity: 0.5586206896551724\n",
      "Sensitivity: 0.865\n",
      "G-Mean: 0.6951308485110729\n"
     ]
    }
   ],
   "source": [
    "result = algorithm.get_result()\n",
    "classification_metrics_kfold(result.variables, route_dataset, dataset_name)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}