How to implement machine learning into an django application

Hello everyone, this is a general question. I am trying to create a web application that filters results through a machine learning algorithm in order to perform classification. Is it possible to do it within an app? If yes, in which part of the app i can perform this analysis. Should it be in views? If i use an asynchronous task queue like celery and redis channels should it be done in the tasks? I know it is a very general question but any advice would be appreciated.
Thanks in advance!!

It depends upon two aspects of your requirements:

  • Are the users making the request expecting to see the results as a response to the request?

  • Does the execution of this algorithm require more time than the timeout value for your server?

If the answer to the first question is “No”, then you can do it as a background task.

If the answer to the second question is “Yes”, then you must do it as a background task.

If you are handling this synchronously in a request, then the the code could be in a view or it could be in a separate module - that’s entirely up to you. It doesn’t really matter from Django’s perspective, it’s a personal choice and how you are most comfortable doing it.

If you’re handling it asynchronously, then it must be in a separate task.

2 Likes