"""Code to accompany Machine Learning Recipes #8.

We'll write a Decision Tree Classifier, in pure Python.
"""

# For Python 2 / 3 compatability
from __future__ import print_function
import sys

# Toy dataset.
# Format: each row is an example.
# The last column is the label.
# The first two columns are features.
# Feel free to play with it by adding more features & examples.
# Interesting note: I've written this so the 2nd and 5th examples
# have the same features, but different labels - so we can see how the
# tree handles this case.
training_data = [
    #normo
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Normal'],
    #oligo
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    #oligoastheno
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    #oligoterato
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    #oat
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Oligoasthenoteratozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '-40', 'Oligoasthenoteratozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '-40', 'Oligoasthenoteratozoospermia'],
    

    #oligo, hyper
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hyperspermia'],
    #oligo, hypo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hypospermia'],
    #oligo, hemato
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    #oligo, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    
    #oligo, hyper, hemato
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    #oligo, hyper, pyo
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    #oligo, hypo, hemato
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    #oligo, hypo, pyo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    #oligo, hemato, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],  
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    
    #oligo, hyper, hemato, pyo
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Oligozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Hematospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '40-', 'Pyospermia'],
    

    #oligoastheno, hyper
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hyperspermia'],
    #oligoastheno, hypo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hypospermia'],
    #oligoastheno, hemato
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #oligoastheno, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],

    #oligoastheno, hyper, hemato
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', ' Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #oligoastheno, hyper, pyo
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    #oligoastheno, hypo, hemato
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #oligoastheno, hypo, pyo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    #oligoastheno, hemato, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', ' Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', ' Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],

    #oligoastheno, hyper, hemato, pyo
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    #oligoastheno, hypo, hemato, pyo
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Oligoasthenozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['1.5-', '15-', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['1.5-', '250-15', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['1.5-', '15-', '39-', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],

    #oligoterato, hyper
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hyperspermia'],
    #oligoterato, hypo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    #oligoterato, hemato
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    #oligoterato, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],

    #oligoterato, hyper, pyo
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    #oligoterato, hyper, hemato
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    #oligoterato, hypo, pyo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    #oligoterato, hypo, hemato
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hematospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hematospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hematospermia'],
    #oligoterato, hemato, pyo
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],

    #oligoterato, hyper, hemato, pyo
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['-5.5', '15-', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '250-15', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '15-', '39-', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    #oligoterato, hypo, hemato, pyo
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Oligoteratozoospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hematospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hematospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hematospermia'],
    ['1.5-', '15-', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '250-15', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '15-', '39-', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    

    #astheno
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],

    #astheno hyper
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hyperspermia'],
    #astheno, hypo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hypospermia'],
    #astheno, hemato
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #astheno, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    #astheno, poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Polyzoospermia'],

    #astheno hyper, hemato
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #astheno hyper, pyo
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    #astheno hyper, poly
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Polyzoospermia'],
    #astheno, hypo, hemato
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    #astheno, hypo, pyo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '40-', 'Pyospermia'],
    #astheno, hypo, poly
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '40-', 'Polyzoospermia'],
    #astheno, hemato, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    #astheno, hemato, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Polyzoospermia'],

    #astheno hyper, hemato, pyo
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],   
    #astheno hyper, hemato, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Polyzoospermia'],
    #astheno, hypo, hemato, pyo
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    #astheno, hypo, hemato, poly
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Hematospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '40-', 'Polyzoospermia'],
    #astheno, hemato, pyo, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Polyzoospermia'],

    #astheno hyper, hemato, pyo, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Polyzoospermia'],
    #astheno, hypo, hemato, pyo, poly
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Asthenozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Hematospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Pyospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '40-', 'Polyzoospermia'],


    #asthenoterato
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],

    #asthenoterato, hyper
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Hyperspermia'],
    #asthenoterato, hypo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Hypospermia'],
    #asthenoterato, hemato
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hematospermia'],
    #asthenoterato, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Polyzoospermia'],

    #asthenoterato, hyper, hemato
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hematospermia'],
    #asthenoterato, hyper, pyo
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, hyper, poly
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hypo, hemato
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hematospermia'],
    #asthenoterato, hypo, pyo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, hypo, poly
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hemato, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, hemato, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', ' Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, pyo, poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Polyzoospermia'],

    #asthenoterato, hyper, hemato, pyo
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, hyper, hemato, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hyper, pyo, poly
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hypo, hemato, pyo
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    #asthenoterato, hypo, hemato, poly
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Hematospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hypo, pyo, poly
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Pyospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '-1', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hemato, pyo, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Polyzoospermia'],

    #asthenoterato, hyper, hemato, pyo, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Polyzoospermia'],
    #asthenoterato, hypo, hemato, pyo, poly
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Asthenoteratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Hematospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Pyospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '40-', '-40', 'Polyzoospermia'],

    
    #terato
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],

    #terato, hyper
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hyperspermia'],
    #terato, hypo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    #terato, hemato
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    #terato, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Polyzoospermia'],

    #terato, hyper, hemato
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    #terato, hyper, pyo
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, hyper, poly
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Polyzoospermia'],
    #terato, hypo, hemato
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    #terato, hypo, pyo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, hypo, poly
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '-40', 'Polyzoospermia'],
    #terato, hemato, pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, hemato, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Polyzoospermia'],
    #terato, pyo, poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Polyzoospermia'],

    #terato, hyper, hemato, pyo
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['-5.5', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, hyper, hemato, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Polyzoospermia'],
    #terato, hyper, pyo, poly
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '-250', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Polyzoospermia'],
    #terato, hypo, hemato, pyo
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['1.5-', '250-15', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    #terato, hypo, hemato, poly
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Hematospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '1-', '-40', '-40', 'Polyzoospermia'],
    #terato, hypo, pyo, poly
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '-40', 'Polyzoospermia'],
    #terato, hemato, pyo, poly
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['5.5-1.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Polyzoospermia'],

    #terato, hyper, hemato, pyo, poly
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hyperspermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['-5.5', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Polyzoospermia'],
    #terato, hypo, hemato, pyo, poly
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Teratozoospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hypospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Hematospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Pyospermia'],
    ['1.5-', '-250', '-39', '-58', 'POSITIF', '-1', '-40', '-40', 'Polyzoospermia'],


    #poly
    ['5.5-1.5', '-250', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Polyzoospermia'],
    #hypo
    ['1.5-', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hypospermia'],
    #hyper
    ['-5.5', '250-15', '-39', '-58', 'NEGATIF', '1-', '-40', '40-', 'Hyperspermia'],
    #hemato
    ['5.5-1.5', '250-15', '-39', '-58', 'POSITIF', '1-', '-40', '40-', 'Hematospermia'],
    #necozoospermia
    ['5.5-1.5', '250-15', '-39', '58-', 'NEGATIF', '1-', '-40', '40-', 'Necozoospermia'],
    #pyo
    ['5.5-1.5', '250-15', '-39', '-58', 'NEGATIF', '-1', '-40', '40-', 'Pyospermia'],
    #azo
    ['5.5-1.5', '250-15', '0', '-58', 'NEGATIF', '1-', '-40', '40-', 'Azoospermia']
    
]

# Column labels.
# These are used only to print the tree.
header = ["volume", "konsentrasi", "jumlah", "jumlah_hidup", "eritrosit", "leukosit", "bergerak", "abnormal", "label"]


def unique_vals(rows, col):
    """Find the unique values for a column in a dataset."""
    return set([row[col] for row in rows])

#######
# Demo:
# unique_vals(training_data, 0)
# unique_vals(training_data, 1)
#######


def class_counts(rows):
    """Counts the number of each type of example in a dataset."""
    counts = {}  # a dictionary of label -> count.
    for row in rows:
        # in our dataset format, the label is always the last column
        label = row[-1]
        if label not in counts:
            counts[label] = 0
        counts[label] += 1
    return counts

#######
# Demo:
# class_counts(training_data)
#######


def is_numeric(value):
    """Test if a value is numeric."""
    return isinstance(value, int) or isinstance(value, float)

#######
# Demo:
# is_numeric(7)
# is_numeric("Red")
#######


class Question:
    """A Question is used to partition a dataset.

    This class just records a 'column number' (e.g., 0 for Color) and a
    'column value' (e.g., Green). The 'match' method is used to compare
    the feature value in an example to the feature value stored in the
    question. See the demo below.
    """

    def __init__(self, column, value):
        self.column = column
        self.value = value

    def match(self, example):
        # Compare the feature value in an example to the
        # feature value in this question.
        val = example[self.column]
        if is_numeric(val):
            return val >= self.value
        else:
            return val == self.value

    def __repr__(self):
        # This is just a helper method to print
        # the question in a rePOSITIFble format.
        condition = "=="
        if is_numeric(self.value):
            condition = ">="
        return "Is %s %s %s?" % (
            header[self.column], condition, str(self.value))

#######
# Demo:
# Let's write a question for a numeric attribute
# Question(1, 3)
# How about one for a categorical attribute
# q = Question(0, 'Green')
# Let's pick an example from the training set...
# example = training_data[0]
# ... and see if it matches the question
# q.match(example)
#######


def partition(rows, question):
    """Partitions a dataset.

    For each row in the dataset, check if it matches the question. If
    so, add it to 'true rows', otherwise, add it to 'false rows'.
    """
    true_rows, false_rows = [], []
    for row in rows:
        if question.match(row):
            true_rows.append(row)
        else:
            false_rows.append(row)
    return true_rows, false_rows


#######
# Demo:
# Let's partition the training data based on whether rows are Red.
# true_rows, false_rows = partition(training_data, Question(0, 'Red'))
# This will contain all the 'Red' rows.
# true_rows
# This will contain everything else.
# false_rows
#######

def gini(rows):
    """Calculate the Gini Impurity for a list of rows.

    There are a few different ways to do this, I thought this one was
    the most concise. See:
    https://en.wikipedia.org/wiki/Decision_tree_learning#Gini_impurity
    """
    counts = class_counts(rows)
    impurity = 1
    for lbl in counts:
        prob_of_lbl = counts[lbl] / float(len(rows))
        impurity -= prob_of_lbl**2
    return impurity


#######
# Demo:
# Let's look at some example to understand how Gini Impurity works.
#
# First, we'll look at a dataset with no mixing.
# no_mixing = [['Apple'],
#              ['Apple']]
# this will return 0
# gini(no_mixing)
#
# Now, we'll look at dataset with a 50:50 apples:oranges ratio
# some_mixing = [['Apple'],
#               ['Orange']]
# this will return 0.5 - meaning, there's a 50% chance of misclassifying
# a random example we draw from the dataset.
# gini(some_mixing)
#
# Now, we'll look at a dataset with many different labels
# lots_of_mixing = [['Apple'],
#                  ['Orange'],
#                  ['Grape'],
#                  ['Grapefruit'],
#                  ['Blueberry']]
# This will return 0.8
# gini(lots_of_mixing)
#######

def info_gain(left, right, current_uncertainty):
    """Information Gain.

    The uncertainty of the starting node, minus the weighted impurity of
    two child nodes.
    """
    p = float(len(left)) / (len(left) + len(right))
    return current_uncertainty - p * gini(left) - (1 - p) * gini(right)

#######
# Demo:
# Calculate the uncertainy of our training data.
# current_uncertainty = gini(training_data)
#
# How much information do we gain by partioning on 'Green'?
# true_rows, false_rows = partition(training_data, Question(0, 'Green'))
# info_gain(true_rows, false_rows, current_uncertainty)
#
# What about if we partioned on 'Red' instead?
# true_rows, false_rows = partition(training_data, Question(0,'Red'))
# info_gain(true_rows, false_rows, current_uncertainty)
#
# It looks like we learned more using 'Red' (0.37), than 'Green' (0.14).
# Why? Look at the different splits that result, and see which one
# looks more 'unmixed' to you.
# true_rows, false_rows = partition(training_data, Question(0,'Red'))
#
# Here, the true_rows contain only 'Grapes'.
# true_rows
#
# And the false rows contain two types of fruit. Not too bad.
# false_rows
#
# On the other hand, partitioning by Green doesn't help so much.
# true_rows, false_rows = partition(training_data, Question(0,'Green'))
#
# We've isolated one apple in the true rows.
# true_rows
#
# But, the false-rows are badly mixed up.
# false_rows
#######


def find_best_split(rows):
    """Find the best question to ask by iterating over every feature / value
    and calculating the information gain."""
    best_gain = 0  # keep track of the best information gain
    best_question = None  # keep train of the feature / value that produced it
    current_uncertainty = gini(rows)
    n_features = len(rows[0]) - 1  # number of columns

    for col in range(n_features):  # for each feature

        values = set([row[col] for row in rows])  # unique values in the column

        for val in values:  # for each value

            question = Question(col, val)

            # try splitting the dataset
            true_rows, false_rows = partition(rows, question)

            # Skip this split if it doesn't divide the
            # dataset.
            if len(true_rows) == 0 or len(false_rows) == 0:
                continue

            # Calculate the information gain from this split
            gain = info_gain(true_rows, false_rows, current_uncertainty)

            # You actually can use '>' instead of '>=' here
            # but I wanted the tree to look a certain way for our
            # toy dataset.
            if gain >= best_gain:
                best_gain, best_question = gain, question

    return best_gain, best_question

#######
# Demo:
# Find the best question to ask first for our toy dataset.
# best_gain, best_question = find_best_split(training_data)
# FYI: is color == Red is just as good. See the note in the code above
# where I used '>='.
#######

class Leaf:
    """A Leaf node classifies data.

    This holds a dictionary of class (e.g., "Apple") -> number of times
    it appears in the rows from the training data that reach this leaf.
    """

    def __init__(self, rows):
        self.predictions = class_counts(rows)


class Decision_Node:
    """A Decision Node asks a question.

    This holds a reference to the question, and to the two child nodes.
    """

    def __init__(self,
                 question,
                 true_branch,
                 false_branch):
        self.question = question
        self.true_branch = true_branch
        self.false_branch = false_branch


def build_tree(rows):
    """Builds the tree.

    Rules of recursion: 1) Believe that it works. 2) Start by checking
    for the base case (no further information gain). 3) Prepare for
    giant stack traces.
    """

    # Try partitioing the dataset on each of the unique attribute,
    # calculate the information gain,
    # and return the question that produces the highest gain.
    gain, question = find_best_split(rows)

    # Base case: no further info gain
    # Since we can ask no further questions,
    # we'll return a leaf.
    if gain == 0:
        return Leaf(rows)

    # If we reach here, we have found a useful feature / value
    # to partition on.
    true_rows, false_rows = partition(rows, question)

    # Recursively build the true branch.
    true_branch = build_tree(true_rows)

    # Recursively build the false branch.
    false_branch = build_tree(false_rows)

    # Return a Question node.
    # This records the best feature / value to ask at this point,
    # as well as the branches to follow
    # dependingo on the answer.
    return Decision_Node(question, true_branch, false_branch)


def print_tree(node, spacing=""):
    """World's most elegant tree printing function."""

    # Base case: we've reached a leaf
    if isinstance(node, Leaf):
        print (spacing + "Predict", node.predictions)
        return

    # Print the question at this node
    print (spacing + str(node.question))

    # Call this function recursively on the true branch
    print (spacing + '--> True:')
    print_tree(node.true_branch, spacing + "  ")

    # Call this function recursively on the false branch
    print (spacing + '--> False:')
    print_tree(node.false_branch, spacing + "  ")


def classify(row, node):
    """See the 'rules of recursion' above."""

    # Base case: we've reached a leaf
    if isinstance(node, Leaf):
        return node.predictions

    # Decide whether to follow the true-branch or the false-branch.
    # Compare the feature / value stored in the node,
    # to the example we're considering.
    if node.question.match(row):
        return classify(row, node.true_branch)
    else:
        return classify(row, node.false_branch)


#######
# Demo:
# The tree predicts the 1st row of our
# training data is an apple with confidence 1.
# my_tree = build_tree(training_data)
# classify(training_data[0], my_tree)
#######

def print_leaf(counts):
    """A nicer way to print the predictions at a leaf."""
    total = sum(counts.values()) * 1.0
    probs = {}
    for lbl in counts.keys():
        probs[lbl] = str(int(counts[lbl] / total * 100)) + "%"
    return probs


#######
# Demo:
# Printing that a bit nicer
# print_leaf(classify(training_data[0], my_tree))
#######

#######
# Demo:
# On the second example, the confidence is lower
# print_leaf(classify(training_data[1], my_tree))
#######

if __name__ == '__main__':


    my_tree = build_tree(training_data)
    
    #print_tree(my_tree)

    

    volume = sys.argv[1]
    konsentrasi = sys.argv[2]
    jumlah = sys.argv[3]
    hidup = sys.argv[4]
    eritrosit = sys.argv[5]
    leukosit = sys.argv[6]
    bergerak = sys.argv[7]
    abnormal = sys.argv[8]

    #volume = '5.5-1.5'
    #konsentrasi = '250-15'
    #jumlah = '-39'
    #hidup = '-58'
    #eritrosit = 'NEGATIF'
    #leukosit = '1-'
    #bergerak = '-40'
    #abnormal = '40-'

    # Evaluate
    testing_data = [
        #['5.5≥...≥1.5', '250≥...≥15', '>39', '≥58', 'NEGATIF', '≤1', '≥40', '≤40']
        [volume, konsentrasi, jumlah, hidup, eritrosit, leukosit, bergerak, abnormal]
    ]

    for row in testing_data:
        print (print_leaf(classify(row, my_tree)))

# Next steps
# - add support for missing (or unseen) attributes
# - prune the tree to prevent overfitting
# - add support for regression