What Is the Idea Behind an Empty Model?

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.

1

1 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest