Classification problems are a broad class of machine learning applications devoted to assigning input data to a predefined category based on its features. If the boundary between the categories has a linear relationship to the input data, a simple logistic regression algorithm may do a …
In the notation of this previous post, a logistic regression binary classification model takes an input feature vector, , and returns a probability, , that belongs to a particular class: . The model is trained on a set of provided example feature vectors, , and …
Simple logistic regression is a statistical method that can be used for binary classification problems. In the context of image processing, this could mean identifying whether a given image belongs to a particular class () or not (), e.g. "cat" or "not cat". A logistic …
For a basic logistic regression image classification exercise, it is usually desirable for the training and test images to have the same dimensions and images are often chosen to be square. However, many datasets provide images with different sizes and aspect ratios for more advanced …
This script demonstrates the relaxation of an ensemble of colliding particles towards the equilibrium, Maxwell-Boltzmann distribution of their speeds. Unlike this previous post, the collision detection and dynamics are handled using NumPy arrays without explicit python loops (except over collision pairs), which improves the performance …
Note: This post has been updated to use the new scipy.special.sph_harm_y function, which has a slightly different call signature to the deprecated scipy.special.sph_harm function (to be removed in SciPy version 1.17.0.) The spherical harmonics are a set of special functions defined on the surface of …
The last episode of 3Blue1Brown's "lockdown math" series posed the problem: given two numbers, and , chosen randomly from the uniform distribution between 0 and 1, what is the proportion that their ratio, when rounded down to the nearest integer, is even? That is, what …
A Babyonian spiral (OEIS A256111) is the figure formed by starting with a zero-vector at the origin and concatenating vectors such that each subsequent vector is the next one longer than the previous one that also lands on a position with integral Cartesian coordinates. That …
Following on from this earlier post, here is a class, TruchetHexes, which generates a pleasing weave-like pattern by tiling the following hexagon shapes in random orientations. A typical image looks like this: This code requires the truchet.py file from this previous post on Truchet tiles.
The following code implements a Quadtree in Python (see the previous blog post for a description of quadtrees). There are three classes: Point represents a point in two-dimensional space, with an optional "payload" (data structure associating the Point with more information, for example the identity …