Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:19:38+00:00 2026-06-02T02:19:38+00:00

I am using cross valind function on a very small data… However I observe

  • 0

I am using cross valind function on a very small data… However I observe that it gives me incorrect results for the same. Is this supposed to happen ?

I have Matlab R2012a and here is my output

crossvalind('KFold',1:1:11,5)

ans =

 2
 5
 1
 3
 2
 1
 5
 3
 5
 1
 5

Notice the absence of set 4.. Is this a bug ? I expected atleast 2 elements per set but it gives me 0 in one… and it happens a lot that is the values are not uniformly distributed in the sets.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:19:40+00:00Added an answer on June 2, 2026 at 2:19 am

    The help for crossvalind says that the form you are using is: crossvalind(METHOD, GROUP, ...). In this case, GROUP is the e.g. the class labels of your data. So 1:11 as the second argument is confusing here, because it suggests no two examples have the same label. I think this is sufficiently unusual that you shouldn’t be surprised if the function does something strange.

    I tried doing:

    numel(unique(crossvalind('KFold', rand(11, 1) > 0.5, 5)))
    

    and it reliably gave 5 as a result, which is what I would expect; my example would correspond to a two-class problem (I would guess that, as a general rule, you’d want something like numel(unique(group)) <= numel(group) / folds) – my hypothesis would be that it tries to have one example of each class in the Kth fold, and at least 2 examples in every other, with a difference between fold sizes of no more than 1 – but I haven’t looked in the code to verify this.

    It is possible that you mean to do:

    crossvalind('KFold', 11, 5);
    

    which would compute 5 folds for 11 data points – this doesn’t attempt to do anything clever with labels, so you would be sure that there will be K folds.

    However, in your problem, if you really have very few data points, then it is probably better to do leave-one-out cross validation, which you could do with:

    crossvalind('LeaveMOut', 11, 1);
    

    although a better method would be:

    for leave_out=1:11
      fold_number = (1:11) ~= leave_out;
      <code here; where fold_number is 0, this is the leave-one-out example. fold_number = 1 means that the example is in the main fold.>
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our cross-platform c-project we are using the macro for the logging purposes: #if
We are using the Dynamic Script Tag with JsonP mechanism to achieve cross-domain Ajax
I built some cross fade rollovers in IE7 using this single image technique: http://jqueryfordesigners.com/image-cross-fade-transition/
I am using this Ajax script below to make cross domain Ajax calls which
I'm trying to develop a cross-platform application using C++ with boost. I typically program
How to make this css code cross browser compatible using jquery. this code only
Can we make cross browser css layouts with CSS positioning, without using float? What
I want to make my C++ project cross platform, and I'm considering using Cygwin/MinGW.
Is there any way to create a pivot and/or cross-tab query using for SQLite
I'm trying to POST some multipart form data to my server using a Browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.