Guessing Number of Clusters in Data

I will start with stating a way to guess the number of clusters and then prove it.

Plot the total error (sum of distance between point and its cluster centre) vs number of clusters.
The point where the slope of this curve changes very steeply is the number of clusters …

Custom Exceptions in python

While writing tests we often need to compare objects defined by us and we then have to compare each attribute of the object one by one.

Let's take an example of a simple Car class. The Car object has two attributes speed and color.

class Car:
    def __init__(self, speed …

Plotting and Animating NetworkX graphs

Modifying neworkX graph using Matplotlib

Let's start with plotting a simple graph using nx.draw:

import networkx as nx

G = nx.Graph()
G.add_nodes_from([1, 2, 3, 4, 5, 6, 7, 8, 9])
G.add_edges_from([(1,2), (3,4), (2,5), (4,5), (6,7), (8,9), (4,7), (1 …