import random


def split(dataset, ratio):
    """
    Split the dataset into a training set and a test set
    :param dataset: dataset top split
    :param ratio: percent of the row in the training set from the dataset
    :return: training set, test set
    """
    trainingSet = []
    testSet = []
    # separate randomly the training and the test set
    for row in range(len(dataset) - 1): # for each row
        # convert the strings, which had to be floats.
        for col in range(2, 4):
            dataset[row][col] = float(dataset[row][col])
        # convert the string, which has to be an int
        dataset[row][4] = int(dataset[row][4])
        # split randomly the set
        if random.random() < ratio:
            trainingSet.append(dataset[row])
        else:
            testSet.append(dataset[row])
    return trainingSet, testSet