4
$\begingroup$

We need train & test data, so what do x and y mean? Does it mean that it divides 15% to the 'x_train', 'x_val', 'y_train', 'y_val' ?

x_train, x_val, y_train, y_val = train_test_split(x, y, test_size=0.15, shuffle=True)
$\endgroup$
1
  • 2
    $\begingroup$ As someone who came from HNQ based only on its title, could the title of this question be clarified, perhaps by adding the context in which this is used? (I don't have any knowledge on this, so I can't give any suggestion) $\endgroup$
    – Andrew T.
    Dec 15, 2021 at 5:36

3 Answers 3

5
$\begingroup$

The test_size=0.15 inside the function indicates the percentage of the data that should be held over for testing/validation.

X_train, X_val, y_train, y_val = train_test_split(
                             X, y, test_size=0.15, random_state=42, shuffle=True)
  • X - independent features(excluding target variable)
  • y - dependent variables, called (target).

So, to train your model you use X_train as the features and y_train as the ground truth. Similarly, when testing you use X_test as the features and y_test to validate the predicted labels.

$\endgroup$
3
$\begingroup$

Think of the (X,y) as your main dataset being a one-to-one mapping between input variables to the target output classification or value. That split function randomly divides the dataset rows so that you end up with disjoint train & test sub-datasets. Each test & train sub-dataset will have number of rows proportional to the specified % size parameter. The split function returns the (X_train, y_train) & (X_test, y_test) parts respectively.

$\endgroup$
0
$\begingroup$

X and y

  • X is a matrix of the features values, each column being one feature, and being known values.

    Each column of X is an independant variable.

  • y is a vector of the target values, being the values you want to try to predict.

    y has only one column and is the dependant/target variable.

  • A row in X anf y is one data sample.

Split

At the begining you will split your data into a train and a test set.

  • So you will have X_train and y_train for the features and target values you will use during the training of your model.

  • And you will have X_test and y_test for the features and target values you will use for the final evaluation of your model.

test_size

test_size=0.15 means that tou will use 15% percent of you data samples (lines) for the test set : X_test and y_test

and the remaining 85% of samples (lines) for the train set : X_train and y_train

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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