All possible shuffles of a 52 cards deck is equal to 52! (52 factorial)
This number is close to 8 * 10^67
or 8 followed by 67 zeros!
6/13π§΅
Here you can clearly see the power of iterables.
You can use a collection that doesn't fit in memory because it's lazily evaluated!
7/13π§΅
Now that we've shuffled the deck, you have to draw K cards from it. My question is, how many possible hands can you draw?
The question, in Math language, is: how many combinations of K cards can you draw from a set of 52 cards? π€
8/13π§΅
Itertools also can help you with that.
Let's suppose K = 10:
all_combinations = it.combinations(all_cards, 10)
Again this value is very big!!!
9/13π§΅
The combinations formula is:
c = n! / (k! * (n-k)!)
c = 52! / (10! * 42!)
c ~ 1.5 * 10^10
Again, huge number! This will pressure the memory!
As you can see, knowing the available tools to help you can make a big difference!
10/13π§΅
The last question is, if you change the previous problem to:
how many possible hands can you draw if when you draw a card, you write it down, put it back on the deck, shuffle and draw again. π€
This is done using the combination_with_replacement method.
11/13π§΅
As you can imagine, this is much bigger than the number of combinations!
Something close to 1.44 * 10Λ17
Following up from my previous thread, let's continue taking a look at some additional itertools methods
Some of them, as you will see, have very similar built-in versions but the key here is: itertools works on iterables and generators that are lazy evaluated collections
1/14π§΅
One example is the method islice. It does slicing but for iterables (potentially endless collections). The main difference is that it doesn't accept negative indexes like regular slicing.
Machine learning goes beyond Deep Learning and Neural Networks
Sometimes a simpler technique might give you better results and be easier to understand
A very versatile algorithm is the Decision Forest
π΄π²π³?
What is it and how does it work?
Let me tell you..
[7 min]
1/10π§΅
Before understanding a Forest, let's start by what's a Tree
Imagine you have a table of data of characteristics of Felines. With features like size, weight, color, habitat and a column with the labels like lion, tiger, house cat, lynx and so on.
2/10π§΅
With some time, you could write a code based on if/else statements that could, for each a row in the table, decide which feline it is
This is exactly what a Decision Tree does
During its training it creates the if/elses