March 2020
Intermediate to advanced
366 pages
9h 8m
English
We are going to write the training method in a separate function; it's a good practice if we later wanted to change our training method. First, we define the signature of our function, as follows:
def train(training_features: np.ndarray, training_labels: np.ndarray):
Thus, we want a function that takes two arguments—training_features and training_labels—and the correct answers corresponding to each feature. Thus, the first argument will be a matrix in the form of a two-dimensional NumPy array, and the second argument will be a one-dimensional NumPy array.
Then, the function will return an object that should have a predict method, which takes new unseen data and labels it. So, let's get started and see how we could train an ...