Python Predictive Models Under the Hood of Flask

And it is not for nothing that I mentioned the phrase “under the hood” in the title of the article, since the analogy with which I would like to begin the article directly concerns the automotive theme.

Which gearbox do you prefer, manual or automatic? As practice shows, most people prefer automatic. The rest, like me, are inclined towards manual. And this is not without reason.

The advantages of the first option are known to everyone, and a few additional words should be said about the second. Firstly, it is the ability to independently determine how much we want to spin our engine, and secondly, getting pleasure from the process itself, and this is not some kind of sadomaso!

It is with a manual transmission that I would like to compare the Flask microframework, designed for creating web applications in the Python programming language.

Due to the above analogies with a manual transmission, and also taking into account all the “Python syntactic sugar”, Flask was chosen to develop a website dedicated to football. plus3s.

As for the football results forecasting model, it is based on the machine learning principles that I described in the article Football analytical program plus3s: forecasting the result of a football match and just playing and the article How to determine the reasons for the achievements and failures of a football club using numbers. However, this program, which was discussed, no longer exists, since its author, that is, me, realized that the future of such developments is “web”. This is primarily more convenient for users, and secondly, it simply protects the code.

At the same time, the great deal of work done was not in vain, and forecasting models based on such “Python” libraries as the decision tree (DecisionTreeClassifier) ​​and random forest (RandomForestClassifier) ​​were successfully applied in the development of a web application based on Flask.

The models work fine and I made a short tutorial video on how to properly use the developed forecasting system.

This video is not about the forecasting model itself (although the principle of the code is briefly touched upon), and not about how it was created, but about what numbers and where to enter to get the result.

But of course, I can't help but mention the shortcomings of this model, namely its “supervised learning.” Trees can get confused when they receive data that is very different from what they were trained on.

For example, we gave the program data on five or six and so on seasons of the championship, and the program began to navigate them quite well. However, the current season that we are monitoring (like the 2016 season, when Leicester became the champion of England), shows completely different figures than the program was trained on. It is logical that it will navigate them worse. Moreover, it, the program, will not even guess what is happening! How can it know that in such and such a year some upstart will be in charge of everything? Although, on the other hand, it is possible that this upstart is simply repeating someone else's path, and then the question is only in the amount of data received by the program.

And this is in such a difficult to predict matter as football!.. Yes, it is much easier to predict the type of plant by the characteristics of the petal!

Of course, everything I write here can be used not only in football, but also for any other purposes related to forecasting. For example, you can make a weather forecast site or go even further and develop a system for predicting the development of diseases. The point is that Flask is quite friendly with “Python” machine learning libraries, although sometimes it makes you nervous. In particular, this concerns importing various libraries to the server. But, to be fair, these are not Flask's problems, but the hosting on which it is “deployed”.

By the way, I chose reg.ru as a hosting provider almost at random, and, in principle, I am satisfied with our interaction.

As you work, you will have to solve problems that arise, but believe me, they are all surmountable. I have made so many different codes work on the server! Sometimes I could only find a solution after several days, but I did. For example, the site, among other things, uses the bs4 parsing library. Initially, the possibility of using this library was limited to only one condition for its installation. And everything worked, but only until a certain day, when a breakdown occurred. I tried in every possible way to understand what the problem was, until I found out that for some reason, in the main code you just need to… import bs4 before Flask itself. But why?! After all, everything was fine before, even without such an import sequence!.. Needless to say, in such cases, the support service, with all due respect to it, is unlikely to tell you anything, and you will have to solve the problem yourself. And such moments do not become less frequent as the project “gets heavier”. So much for the manual transmission!

In general, there will definitely be difficulties, but, as I already said, they are all solvable.

Finally, I will note the relative unpopularity of Flask in comparison, for example, with Django. I suppose that this is due to the fact that most web projects “run” just fine on an automatic transmission. However, if you need to create something “heavier” and you like to control everything yourself, then you may need Flask for development.

By the way, if anything happens, please contact me! I'll help as much as I can.

P.S.

Video tutorials on Flask can be viewed on YouTube Here.

A good article on installing Flask on reg.ru hosting is located at this link. This article also contains a link to the provider's official material, but both articles should be read together.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *