Preprocessing the dataset

The next step is to split the data points into training and test sets, as we have done before. But, before we do that, we have to prepare the data for OpenCV as follows:

  • All feature values in X must be 32-bit floating point numbers
  • Target labels must be either -1 or +1

We can achieve this with the following code:

In [4]: import numpy as np
... X = X.astype(np.float32)
... y = y * 2 - 1

Now we can pass the data to scikit-learn's train_test_split function as we did in the earlier chapters:

In [5]: from sklearn import model_selection as ms
... X_train, X_test, y_train, y_test = ms.train_test_split(
... X, y, test_size=0.2, random_state=42
... )

Here, I chose to reserve 20 percent of all data points for the test set, but you can adjust this number according to your liking.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.149.238