Python dict is useful. The access to a nested item can be tedious, however. For example,
data = { "hosts": { "name": "localhost", "cidr": "127.0.0.1/8", } } Here, data["hosts"]["cidir"] would get you "127.0.0.1/8", but all those quotes and brackets can be annoying to type and read.
... Continue reading.
The stdlib logging package in Python encourages the C-style message format string and passing variables as arguments to its log method. For example,
logging.debug("Result x = %d, y = %d" % (x, y)) # Bad logging.debug("Result x = %d, y = %d", x, y) # Good or
... Continue reading.
Suppose we ran an A/B test with two different versions of a web page, $a$ and $b$, for which we count the number of visitors and whether they convert or not. We can summarize this in a contingency table showing the frequency distribution of the events:
... Continue reading.
I was reading an article about visualization techniques using multidimensional scaling (MDS), the correspondence analysis in particular. The example used R, but as usual I want to find ways to do it on Python, so here goes.
The correspondence analysis is useful when you have a two-way contingency table for which relative values of ratio-scaled data are of interest.
... Continue reading.
There are several ways to run principal component analysis (PCA) using various packages (scikit-learn, statsmodels, etc.) or even just rolling out your own through singular-value decomposition and such. Visualizing the PCA result can be done through biplot. I was looking at an example of using prcomp and biplot in R, but it does not seem like there is a comparable plug-and-play way of generating a biplot on Python.
... Continue reading.
There are numerous pieces of duplicate information served by multiple sources on the web. Many news stories that we receive from the media tend to originate from the same source, such as the Associated Press. When such contents are scraped off the web for archiving, a need may arise to categorize documents by their similarity (not in the sense of meaning of the text but the character-level or lexical matching).
... Continue reading.
Finally got around to find this out by Googling. It’s a useful function so I reproduce it here for copy & paste:
def inside_polygon(x, y, points): """ Return True if a coordinate (x, y) is inside a polygon defined by the list of verticies [(x1, y1), (x2, y2), .
... Continue reading.