Gangadhar Goud
Gangadhar Goud

Reputation: 13

too many values to unpack (expected 3)

While splitting the data into training and testing using python, I am getting following error

" too many values to unpack (expected 3)"

Here's my code:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train = train_test_split(features,prices, test_size=0.2, random_state=10)
print("Training and testing split was succesful")

This is the expected output: 'Training and testing split was successful'.

Upvotes: 1

Views: 4049

Answers (2)

code-life balance
code-life balance

Reputation: 319

This is the document of train_test_split in sklearn: sklearn.model_selection.train_test_split.

Here is the return:

splitting : list, length=2 * len(arrays)

List containing train-test split of inputs.

If you input features and prices, that means you put two inputs, each of which would be split into two parts, training and testing. So in order to obtain them, you should use X_train, X_test, y_train, y_test, but you missed the last parameter.

Possibly you can correct your code like this:

from sklearn.model_selection import train_test_split 

X_train, X_test, y_train, y_test = train_test_split(features,prices, test_size=0.2, random_state=10) 
print("Training and testing split was successful")

Upvotes: 0

bkbb
bkbb

Reputation: 257

Looks like you missed y_test.

Try this:

X_train, X_test, y_train, y_test = train_test_split(features,prices, test_size=0.2, random_state=10) 

Upvotes: 1

Related Questions