CODEX

Or how to make your project pip install-able

Creating a Python package isn’t typically something a developer does routinely, so when it happens, you may end up losing time and nerves in small details you forgot.

Here is a (hopefully) simple gentle guide easy to follow for proceeding. Just take it as a small recipe when you need to cook your Python package once in a while.

Image for post
Image for post
Creating a Python package…

Let’s go step by step:

Prerequisite

You have first to install the packages setuptools, wheel, and twine:

Project structure

The first-level folder structure of your project (from now on called mypackage) should look like this:

|___ LICENCE |___ mypackage/…


A method for hashing strings based on the weights of an Artificial Neural Network trained on them

Yesterday talking with one of my machine learning students Thomas Mathieu in Lewagon, we got an idea: what if the parameters of a machine learning model could somehow encode the data used to train this model? With nice properties on top of it?

A hash function is a function taking an input and giving an output such that:
1. it’s (nearly) impossible to find out the input from the output
2. the output is of fixed size
3. given an input, you get always the same output

Hash functions are used for example to keep passwords safe: their hash instead…


How to simply extend it to multiple states in multiple dimensions with numpy

Invented by Conway in 1970, the game of life is a quite fascinating application of cellular automata with deep implications in computer science and mathematics. Let’s just see here how to make a pretty flexible multi-valued and multi-dimensional implementation of them leveraging numpy.

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors
import imageio
from IPython.display import display, Image
cmap = colors.ListedColormap([‘blue’, ‘white’, ‘red’])
N = 15

We begin with defining a grid with random integer values in (0, 1, 2) on its squares:

arr = np.random.randint(3, size=N * N, dtype=np.int8).reshape(N, N)

Then for…


Derived from a modification of the Binet formula

What is the Fibonacci sequence? It’s easy to define: the first element is 1, the second is 2, and the following elements are the sum of the two previous ones: the 3rd element is 3 (2 +1), the 4th is 5 (3+2), the 5th is 8 (5+3) etc.

Tonight on the Python Discord channel, a user came up with a challenge: find a faster Python implementation to compute the elements of the Fibonacci sequence than this one:

Image for post
Image for post

Challenge accepted. I already knew there is a closed form (direct formula) to compute the Fibonacci values, so I thought it would be…


Gradient descent is a major technique for training ML/DL models. Let’s have a closer look at it and implement a simple example from scratch in Python illustrating the main basic concepts around gradient descent.

Gradient descent is omnipresent in the training of neural networks and other machine learning models. Each time you have a model which parameters are updated during the training according to a loss function, you can be almost certain that there is gradient descent under the hood. Here we will see how gradient descent works along a very simple linear regression example.

But before starting, what is a gradient and why descend it?

Gradient descent, graphically

Imagine you have to approximate a dataset (X, y) where X represents the features of your datapoints and y the target values (to predict) on those datapoints. The…


A model to simulate the propagation of epidemics like Covid-19 (but not only…)

Note from the editors: Towards Data Science is a Medium publication primarily based on the study of data science and machine learning. We are not health professionals or epidemiologists, and the opinions of this article should not be interpreted as professional advice. To learn more about the coronavirus pandemic, you can click here.

Unless you spent these last few months in a cave in the end of the world (but then you’re probably not reading this article), you couldn’t escape the information about the Covid-19 pandemic. The difficulty to model its evolution is striking. In the US for example, a…

Manuel Capel

Data scientist and backend engineer for many years now

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