I have to classify images using python and cv2. Before training the model, we have to first create an empty model using
cv2.ml.KNearest_create() I understand that this line of code creates an empty model, but what does that mean? When I think of a model, I generally imagine an equation like y = mx + b or y = ax^2 + bx + c. I'm curious as to what an empty model object looks like and how it can be used to fit training data.
11 Answer
The KNearest_create function instantiates the k-nearest neighbor class. It's no different than instantiating the follow "Example" class:
class Example(object): def __init__(self): self.data = [] example = Example() In the case of some machine learning, like neural networks, you might initialize the weights with random data. However, none of this has to be during the instantiation of the class. It could be don't when the fit/train function is called. This is a paradigm within programming.
You can check out Sklearn's implementation of K Nearest Neightbor to see there isn't much going on apart from declaring variables.