简体   繁体   English

你如何在 ML 中实现 make_folds function

[英]how do you implement make_folds function in ML

How do you implement make_folds function in ML如何在 ML 中实现 make_folds function

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 x 是 numpy 数组

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或直接使用https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html如果您想进行 Kfold 验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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