July 2017
Intermediate to advanced
382 pages
9h 13m
English
However, since we are working with OpenCV, this time, we want to make sure the input matrix is made up of 32-bit floating point numbers, otherwise the code will break:
In [2]: import numpy as np... X = X_raw.astype(np.float32)
Furthermore, we need to think back to Chapter 4, Representing Data and Engineering and Features, and remember how to represent categorical variables. We need to find a way to represent target labels, not as integers but with a one-hot encoding. The easiest way to achieve this is by using scikit-learn's preprocessing module:
In [3]: from sklearn.preprocessing import OneHotEncoder... enc = OneHotEncoder(sparse=False, dtype=np.float32)... y = enc.fit_transform(y_raw.reshape(-1, 1))
Read now
Unlock full access