In this article we are going to look at how to create Venn Diagrams with Python. Venn Diagrams are a great invention and are a really handy way to reason about sets. Sets themselves are very important, not just because of the role they play in Mathematics, but also because they are a powerful tool for helping to solve many computational problems.
Venn Diagrams are a way to represent the relationships between sets. So, before we dive in to how to create them with Python, let’s review some set operators. Check out the code below.
Notice the chaining of string…
I’ve been enjoying reading A Programmer’s Introduction to Mathematics by Jeremy Kun recently. After the introduction, the first main topic it covers is a neat trick for sharing secrets (encrypting messages) so that they can be decoded using polynomial functions.
Being a firm believer in learning by doing, I immediately got stuck in and started exploring. It has been some time since I worked much with polynomials, so to get a feel for what I was doing, I wrote a Python program to help me visualise polynomial functions with given coefficients. …
In this post we are going to use Python to explore the story of the Baltimore Stockbroker.
If you were in the fortunate position to have some money to invest and you received a series of letters through your door from a stock broker in Baltimore claiming to have a secret formula for making successful predictions about stock prices, you would be sceptical, right?
What if he backed up his claim by sending you 10 letters in the following weeks, each one successfully predicting whether certain stocks would rise or fall? …
In this article we are going to learn how to do some basic sentiment analysis with Python, using a wordlist-based approach and the
First, you will need to install the package:
pip install afinn
pip3 install afinn on Mac/Linux
You will also need to install the following packages in the same way if you haven’t already:
The basic idea with the
afinn package is that we have a wordlist which has a score in terms of positivity or negativity assigned to each word, ranging from
-5 (very negative) to
In this post we are going to explore conditional probability with Python. Here’s a fun and potentially tricksome question about probabilities:
In a family with two children, what is the probability that, if at least one of the children is a girl, both children are girls?
First of all let’s state a couple of assumptions which are not realistic in the “real world,” but which are fairly standard for theoretical probability questions.
In this article we are going to use Python to test whether a coin is fair. We will do this by making use of the
statsmodels package to perform a hypothesis test.
The problems we will be solving will be of the form:
I flipped a coin 100 times and it landed on heads 55 times. Can I conclude the coin is biased towards heads?
Python provides many excellent tools for working with data and statistics. These include libraries like
matplotlib and, in the case of today's task,
statsmodels. In order to use these tools you will…
Copy/pasting the code breaks the formatting (at least removes blank lines). I know this is a platform problem, but maybe you could help by providing a link to a gist or some such?
In this article we are going to learn about Simpson’s Paradox and explore it with Python programming.
Simpson’s Paradox is where data appears to tell a different story when treated as a whole than when its component parts are considered. There are some famous cases of this paradox which you can read about on Wikipedia. The purpose of this article is to explore the paradox by means of a specific example and the use of Python programming.
The data for this example is taken from a YouTube video by a Harvard Lecturer as part of a Statistics 110 course. …
The Binary Search Algorithm is fundamental in Computer Science. It is a very clever algorithm which reduces the time needed to search for items in large datasets dramatically compared to less efficient approaches.
It is important to note that in order to use binary search, your data must be sorted. Some people get mixed up with sorting algorithms and searching algorithms, grouping them together in their thinking, but it is well worth taking a moment to organise your “algorithm toolkit” a little and make sure that searching and sorting each have their own section. …
Fizz Buzz is a classic coding challenge based on a game played at school in Maths lessons.
Fizz Buzz is a game for two or more players. Take it in turns to count aloud from 1 to 50, but each time you are going to say a multiple of 3, replace it with the word “fizz”. For multiples of 5, say “buzz” and for numbers which are multiples of both 3 and 5, say “fizz, buzz”.
Have a go at writing some Python code to simulate this game now. Your version should just print out a number, or “fizz”, “buzz”…