Is there any pytorch native alternative of sklearn KFold()?

username: SouthTorch
cooked: <p>Many people use the following code to kfold split the dataset:</p>
<pre><code class="lang-auto">from sklearn.model_selection import KFold
kfold = KFold(n_splits=k_folds, shuffle=True)
for fold, (train_ids, test_ids) in enumerate(kfold.split(dataset)):
</code></pre>
<p>I just want to know other pytorch native ways. Thanks. Just feel not to import too much stuff.</p>
<p>A follow up question:<br>
If I want to do some machine learning stuff instead of deep learning, do I need to learn sklearn? Does pytorch include those modules? Thanks.</p>

username: ptrblck
cooked: <p>I;m not aware of a native PyTorch implementation of <code>KFold</code> and would generally recommend to use implemented and well tested modules (in this case from <code>sklearn</code>) instead of reimplementing the same functionality (and potentially hitting bugs) unless you have a strong reason to do so.</p>
<aside class="quote no-group" data-username="SouthTorch" data-post="1" data-topic="153302">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/c89c15/48.png" class="avatar"> SouthTorch:</div>
<blockquote>
<p>If I want to do some machine learning stuff instead of deep learning, do I need to learn sklearn?</p>
</blockquote>
</aside>
<p>It depends which models and use cases you would like to work on, but <code>sklearn</code> is certainly a good library to be familiar with.</p>
<aside class="quote no-group" data-username="SouthTorch" data-post="1" data-topic="153302">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/c89c15/48.png" class="avatar"> SouthTorch:</div>
<blockquote>
<p>Does pytorch include those modules?</p>
</blockquote>
</aside>
<p>Some of them should be available (their neural network classes), but other modules (e.g. from the random tree classes) might not be available natively (you might find some PyTorch ports on GitHub, but I haven’t checked it).</p>

username: SouthTorch
cooked: <p>Thanks, ptrblck! <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/grinning.png?v=12" title=":grinning:" class="emoji" alt=":grinning:" loading="lazy" width="20" height="20"></p>