简体   繁体   中英

how do you implement make_folds function in ML

How do you implement make_folds function in ML

def make_folds(x, num_folds):
    """ Divides the array `x` along axis-0 into a list of equal-sized 
    sub-arrays.

x is numpy array

you could try something like this:

def make_folds(x, num_folds):
    """ Divides the array `x` along axis-0 into a list of equal-sized 
    sub-arrays."""
    assert len(x)%num_folds == 0, "Given array can not be split into {} equal-size subarrays".format(num_folds)
    return np.split(x, num_folds)

or directly using https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html if you want to do Kfold validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM