close

[Solved] TypeError: Singleton array array(True) cannot be considered a valid collection

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: Singleton array array(True) cannot be considered a valid collection 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 TypeError: Singleton array array(True) cannot be considered a valid collection Error Occurs?

Today I get the following error TypeError: Singleton array array(True) cannot be considered a valid collection in Python.

How To Solve TypeError: Singleton array array(True) cannot be considered a valid collection Error ?

  1. How To Solve TypeError: Singleton array array(True) cannot be considered a valid collection Error ?

    To Solve TypeError: Singleton array array(True) cannot be considered a valid collection Error

    stratifyarray-like, default=None If not None, data is split in a stratified fashion, using this as the class labels.

  2. TypeError: Singleton array array(True) cannot be considered a valid collection

    To Solve TypeError: Singleton array array(True) cannot be considered a valid collection Error

    stratifyarray-like, default=None If not None, data is split in a stratified fashion, using this as the class labels.

Solution 1


Per the sklearn documentation:

stratifyarray-like, default=None If not None, data is split in a stratified fashion, using this as the class labels.

Thus, it does not accept a boolean value like True or False, but the class labels themselves.

So, you need to change:

X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = True)

to:

X_full_train, X_full_test, Y_full_train, Y_full_test = train_test_split(X_values_full, Y_values, test_size = 0.33, random_state = 42, stratify = Y_values)

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

Leave a Comment