0
$\begingroup$

I wrote some code based on this article.

In the code in the article they have created a partition of 80 percent test and 20 percent data

#What percentage of data you want to keep for training
percentage = 80
partition = int(len(hog_features)*percentage/100)

Later they have created the following variables, the data frame is two dimensions np array --- data_frame[hog_features,labels]:

x_train, x_test = data_frame[:partition,:-1],  data_frame[partition:,:-1]
y_train, y_test = data_frame[:partition,-1:].ravel() , data_frame[partition:,-1:].ravel()

clf.fit(x_train,y_train)

now what I don't understand is why for the second dimension of the array (the labels) for the x variables they're including everything except the last value and for the y variables the second dimension of the array is just including the last element of the array from what I can understand using array slicing (Maybe I'm wrong).

$\endgroup$

1 Answer 1

0
$\begingroup$

The answer to your questions is simply : that is how training works :

The training set is a matrix in which the last column correspond to the labels and the rest correspond to the samples.

When slicing the matrix, you have two parts: the first one concerns the rows, the second one concerns the columns.

ROWS:

:partition means in fact the first 80% rows - this concerns the training set x_train, y_train

partition: means the last 20% rows - concerns the test set, x_test and y_test

COLUMNS:

:-1 mean all but the last column - concerns x_train and x_test

-1: mean just the last column - concerns y_train and y_test

Therefore, here you get for x_train and x_test everything but the last value. Be careful, in fact you get 80% of the data is for x_train (:partition) and 20% is for x_test (partition:). Now, for the labels you get only the last column, and 80% of the rows are for y_train while 20% of the rows are for y_test.

One more detail, your x_train and y_train is a 5D array, according to the documentation.

$\endgroup$

Your Answer

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

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