[Python] Python mlExtend cross_val error on cross validation. : 'index 5 is out of bounds for...

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I´m trying to do a cross validation with OneRClassifier. I use from sklearn.model_selection import KFold, train_test_split, cross_val_score for cross validation. I have four dimensional data for starters. The fourth is the label column and first three are features. This is the print for the X also known as features when encoded with label encoder:

    [[ 0 0 9]
    [ 0 6 9]
    [ 0 3 8]
    [ 0 9 4]
    [ 0 3 8]
    [ 0 9 12]
    [ 0 1 2]
    [ 0 0 0]
    [ 0 9 5]
    [ 0 7 12]
    [ 0 5 13]
    [ 0 3 1]
    [ 0 9 8]
    [ 0 5 13]
    [ 0 0 11]
    [ 0 3 7]
    [ 0 10 14]
    [ 0 2 4]
    [ 0 4 3]
    [ 0 3 4]
    [ 0 3 12]
    [ 0 3 13]
    [ 0 8 10]
    [ 0 8 4]
    [ 0 8 1]
    [ 0 8 13]
    [ 0 3 8]
    [ 0 4 6]
    [ 0 5 1]
    [ 0 2 12]]


    This is the print for the y

    [5 2 5 0 5 0 5 5 0 2 5 1 0 5 5 5 3 5 5 5 5 1 5 5 5 5 5 5 4 5]


    The shapes are for X (30, 3) and for y (30,).

    accuraciesOneR = cross_val_score(oneR, X, y, cv=kf, scoring='accuracy', error_score='raise')


    This produces an error 'index 5 is out of bounds for axis 0 with size 3' on the cross validation. As i can see the shapes are correct. However i might be wrong. If you can advice me please.

    This is a cross validation of data with oneR in python. I expected the cross validation to work without errors and give me results.

    Continue reading...

Compartilhe esta Página