0
$\begingroup$

I am getting ValueError: too many values to unpack (expected 2) from this code:

(x_train, y_train), (x_test, y_test) = data
print(x_train.shape)  
print(y_train.shape)  
print(y_train[:3])  

I checked similar questions in this error but couldn't solve it.

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ I think You should use X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) to split the data, you can't assign dataframe directly to tuples $\endgroup$ Nov 1 '21 at 16:00
1
$\begingroup$

You are trying to unpack the data variable into two separate pieces, each of which should contain another two outputs (an x and y) variable. However, data is simply a single output, which is a pandas dataframe for which unpacking doesn't work. Based on the code you provided it seems you are trying to split your data into a training and test dataset. This does not work this way if you have the data stored as a single dataframe. You will have to split the manually yourself into a feature array and an array of values you are trying to predict, which you can then split into a training and test dataset using the train_test_split function from scikit-learn.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.