0
$\begingroup$

I'm working on this dataset. I'm trying to select features using Random Forest. This is the relevant code:

x_train, y_train, x_test, y_test = train_test_split(train, test_size = 0.3)

sel = SelectFromModel(RandomForestClassifier(n_estimators=100))
sel.fit(x_train, y_train)
sel.get_support()
selected_feat = x_train.columns[sel.get_support()]

The code x_train, y_train, x_test, y_test = train_test_split(train, test_size = 0.3) throws the following ValueError:

Traceback (most recent call last):
  File "C:/Users/security/Downloads/AP/Boston-Kaggle/Boston.py", line 25, in <module>
    x_train, y_train, x_test, y_test = train_test_split(train, test_size = 0.3)
ValueError: not enough values to unpack (expected 4, got 2)

I don't know what it means by not enough values. The dataset has a big dimension.

$\endgroup$
1
$\begingroup$

This is the implementation of the train_test_split function

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

Split your train into X and y and try again!

$\endgroup$
  • $\begingroup$ What are the parameters X and y before test_size? $\endgroup$ – Andros Adrianopolos Jul 19 at 9:51
  • $\begingroup$ It's your train splitted in 2, X are all the features, y is your target variable. Separate the features from the target and apply the train_test_split $\endgroup$ – Blenz Jul 19 at 9:52

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.