human
I am working on the file "04 - Applied ML/homework04.ipynb".
The first task is:
Utility functions
For the following part of the exercise, we created some utility functions that we use here and could be reused for other tasks.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

# this could have been done in a simpler way for this homework,
# but it might be useful to have such a powerful function for other uses,
# hence we decide to keep it here so that other could use it too :)

def split(X, y, ratios):
    """
    Split X and y given some ratios
    
    Parameters
    ----------
    X : ndarray
    train matrix
    
    y : ndarray
    test matrix
    
    ratios : list(int)
    ratios on how to split X and y

    Returns
    -------
    out : tuple(ndarray)
    Output one tuple of first, the splits of X and then, the splits of y 
    """
    assert np.sum(ratios) < 1, "sum of ratios cannot be greater than 1"
    assert len(ratios) >= 1, "at least one ratio required to split"
    
    def inner_split(X, y, ratios, acc_X, acc_y):
        ratio, *ratios_remaining = ratios
        X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=ratio)

        if len(ratios_remaining) == 0:
            acc_X.extend([X_train, X_test])
            acc_y.extend([y_train, y_test])
            acc_X.extend(acc_y)
            return tuple(acc_X)
        else:
            acc_X.append(X_train)
            acc_y.append(y_train)
            return inner_split(X_test, y_test, [r/(1.0 - ratio) for r in ratios_remaining], acc_X, acc_y)
    
    return inner_split(X, y, ratios, [], [])

def predict(clf, X_train, y_train, X_test):
    """
    Using a classifier, train with training data it using to fit testing labels
    and then predict some labels of testing data.
    
    It also times the different steps.
    
    Parameters
    ----------
    clf: sklearn classifier
    classifier
    
    X_train: ndarray
    training data
    
    y_train: ndarray
    training labels
    
    X_test: ndarray
    testing data

    Returns
    -------
    out : ndarray
    Output the prediction of labels
    """
    start_time = time()
    print("Prediction computations started...")
    clf.fit(X_train, y_train)
    train_time = time() - start_time
    pred = clf.predict(X_test)
    prediction_time =...