Five-minute web apps with Python.

Image for post
Image for post

The Flask micro web framework for Python allows for rapid development of web applications. Apps can be deployed to any free web hosting service, but one is particular makes the process seamless, and that is PythonAnywhere.

The Example:

Below is the full code for a (very) simple application, explained in detail further down. For the sake of simplicity and speed, everything is kept inside one Python file, including the HTML which is normally separate:

Brief explanation for those unfamiliar with Flask or HTML

This application is asking the user for data, sending a request to the server with the HTTP method ‘POST’, and then returning a string as HTML.

The “source” attribute of the form tag determines which page calls which function. For example, “example.com/page_name” calls whichever function is decorated by “@app.route(/page_name)”. …


Image for post
Image for post

Regression is fundamental to Predictive Analytics, and a good example of an optimization problem. The simplest cases of regression are calculable by hand (the results of which we can verify with Python). Below is the linear regression model of some predictor variable ‘x’ with response variable ‘y’.


Image for post
Image for post

Populations that undergo a fixed set of age transitions can be modeled as a system of linear equations, from which age distributions can be calculated.

As a brief review of linear algebra, a system of linear equations can be represented as a matrix equation of the form Ax = b. In this form, ‘A is the set of coefficients as some m × n matrix, ‘x is some input vector in n, and ‘b’ is the product of ‘A’ and ‘x’ as an output vector in m, shown below:

TableAnalysis

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store