close

[Solved] scikit-learn error: The least populated class in y has only 1 member

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error scikit-learn error: The least populated class in y has only 1 member in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How scikit-learn error: The least populated class in y has only 1 member Error Occurs?

Today I get the following error scikit-learn error: The least populated class in y has only 1 member in python.

How To Solve scikit-learn error: The least populated class in y has only 1 member Error ?

  1. How To Solve scikit-learn error: The least populated class in y has only 1 member Error ?

    To Solve scikit-learn error: The least populated class in y has only 1 member Error The problem was that train_test_split takes as input 2 arrays, but the y array is a one-column matrix. If I pass only the first column of y it works.

  2. scikit-learn error: The least populated class in y has only 1 member

    To Solve scikit-learn error: The least populated class in y has only 1 member Error The problem was that train_test_split takes as input 2 arrays, but the y array is a one-column matrix. If I pass only the first column of y it works.

Solution 1

The problem was that train_test_split takes as input 2 arrays, but the y array is a one-column matrix. If I pass only the first column of y it works.

train, xtest, ytrain, ytest = train_test_split(X, y.iloc[:,1], test_size=1/3,
  random_state=85, stratify=y.iloc[:,1])

Solution 2

remove stratify=y while splitting train and test data

xtrain, xtest, ytrain, ytest = train_test_split(X, y, test_size=1/3, random_state=85)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read