# 105 cheat sheet 1

### Machine Learning Tasks

1\) Regression

* Predicts continuous values based on past scores

2\) Classification

* Predicts categories&#x20;
  * Binary
  * Multiple Class

3\) Clustering

* Groups data without labels

### Counting Methods

1\) Repetition Allowed

$$
n^k , \text {where n is number of possibilities, and k is boxes}
$$

2\) No repetition

$$
n \* (n-1) \* (n-2)....., \text { where n is the number of possibilities}
$$

3\) At least one/more repeated digits

$$
n^k - (n\*\[n-1] \*\[n-2]...)
$$

### Set Theory + Probability

{% hint style="danger" %}

### Just because something has two possible results doesn't mean each result is equally likely

{% endhint %}

$$
A \cap B : \text {intersect}
$$

$$
A \cup B : union
$$

{% hint style="info" %}
**Mutually exclusive** means that two or more events, conditions, or situations **cannot happen at the same time**. If one occurs, the other(s) **must not**.
{% endhint %}

Addition Rule/Inclusion-Exclusion Principle

* For the inclusion-exclusion principle, the goal is to add all portions (in a venn diagram) and minus all intersections.

{% hint style="info" %}
Why intersections only?

That's because there is double counting of the intersection when you add P(A) + P(B).
{% endhint %}

$$
P (A \cup B) = P(A) + P(B) - P (A \cap B)
$$

{% hint style="warning" %}
However, if events A and B are mutually exclusive, then Addition Rule will not apply
{% endhint %}

$$
P(A \cup B) = P(A) + P(B)
$$

Complement Rule

$$
P(A^\complement) = 1- P(A)
$$

Conditional Probability

* Given event A, what is the probability of B

$$
P (A|B) = \frac {P (A\cap B)}{P(B)}
$$

Bayes Theorem

* Reverse of conditional probability
* Given event B, what is the chance event B was caused by event A

$$
P(A|B) = \frac {P(B|A)P(A)}{P(B)}
$$

{% hint style="info" %}
If you see Given/If/Assuming in a question, IT is a conditional probability
{% endhint %}

Independence

* When occurrence of one event does not affect probability of other event occurring.

{% hint style="info" %}
Mutually exclusive is very different from independence.

Independence means cooking a meal does not change what happens when you  watch an anime. They don't affect each other at al.

If two events are mutually exclusive, ie. you are choosing between to eat a apple or banana, but being mutually exclusive means that you can't eat both at the same time.
{% endhint %}

If two events are independent:

* As long as one is true, the rest is true

$$
P ( A \cap B) = P(A) \* P(B)
$$

$$
P (A|B) = P(A)
$$

$$
P(B|A) = P(B)
$$

{% hint style="info" %}
The opposite of independence is dependence, meaning that the an event is affected by another event.
{% endhint %}

Joint Probability

* The probability of both event A and event B occuring is

$$
P( A \cap B)
$$

Marginal Probability

* Sum over joint probabilities

$$
P(A) = P( A \cap B) + P(A \cap B^ \complement )
$$

Law of Total Probability

* The events form a partition of the sample space.
* "The total probability of A is the sum of the probabilities of A happening in each scenario, weighted by how likely each scenario is."

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FgDQAyzmXTjlGGfTggt24%2Fimage.png?alt=media&#x26;token=f546762d-b127-4efb-aa68-4845f642b456" alt=""><figcaption><p>Only if Event B is mutually exclusive and exhaustive</p></figcaption></figure>

### Combination + Permutation

{% hint style="info" %}
Keywords:

* Does order matter?
* Are they looking for a pair?
* Anything hinting that it should be distinct<br>

Other Tips:

* Multiplication ⇒ Adding probabilities
* Power ⇒ Independent probabilities happening at once (Ie. Not sharing the same birthday/Dice is a 6 and a Coin is Heads)
  {% endhint %}

Combination - Order does not matter

$$
{n \choose r} = \frac {n!}{r!(n-r)!}
$$

{% hint style="warning" %}
There may come times where you need to answer via cases. This is when:

1\) There are multiple constraints (at least 2 boys and 3 girls)

2\) There are multiple valid possibilities ( 1 team with 2 people, 2 teams with 1 person)

3\) When the problem asks for exact numbers/items from different groups

\
! Have you checked inverse/duplicate instances?
{% endhint %}

Special Chooses

1\) Select all

$$
{n \choose n} = 1
$$

2\) Select none

$$
{n \choose 0} = 1
$$

3\) Symmetry

* Ie. When choosing a team of 3 from 10 people, choosing 3 people for the team, or choosing 7 people to leave out from the team results in the same result

$$
{10 \choose 3} = {10 \choose 7}
$$

* This is what makes combination's "order doesn't matter" unique
* So, the result of combinations should not change the outcome

Permutation - Order matters

$$
P (n,r) = \frac {n!}{(n-r)!}
$$

where n is total number of items, and r is the number of items to arrange

* 0! = 1

{% hint style="warning" %}
This formula cannot be directly used all the time, because the number of items may have conditions. (ie, at least 3 items of x, and 4 items of y)

\
In these cases, use combination formula to find out first.
{% endhint %}

### Discrete and Continuous Random Variables

Random Variables

* An outcome with a value that is random. (Ie. Number of heads in 5 coin flips = \[random])
* Outcome can be related to being discrete or continuous
* Can be expressed with a table&#x20;

Discrete Distribution

* Probability Distribution of a&#x20;

<table><thead><tr><th width="306">Number of Toys (Random Variable/Output)</th><th>Number of Kids</th></tr></thead><tbody><tr><td>0 toys</td><td>9 kids </td></tr><tr><td>1 toy</td><td>6 kids</td></tr><tr><td>2 toys</td><td>15 kids</td></tr></tbody></table>

* From the table, we can gain the probability a child has x toys.
  * This creates pmf, which can be displayed in a table.<br>

| x      | P(X=x)              |
| ------ | ------------------- |
| 0 toys | 9/total kids = 0.3  |
| 1 toy  | 6/total kids = 0.2  |
| 2 toys | 15/total kids = 0.5 |

* Now, from pmf, we can find the total chance the outcome, or less than it can be achieved.
  * Ie. What's the chance a kid has 1 or less toys?
  * Ie. How likely is the x and less? (random variable)
  * This is the cdf - summing up all the possibilities and less. (Giving a probability for a set range of outcomes)

| Discrete Distribution                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Continuous Distribution                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <ul><li>Takes countable values</li><li>No. of children, no. on die</li><li>Ie. pick ball,max/min, count of days</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | <ul><li>Take uncountably infinite values, intervals</li><li>Time taken to finish task, height, weight</li><li>Ie. Integral, measuring time/length</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| P(X =x) is positive for specific values                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | P(X=x) =0 for exact values                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| <p>PMF (probability mass function)</p><ul><li>Exact chance of a value</li></ul><p></p><p>Properties</p><ul><li><p>0 ≤ 𝑝ₓ(𝑥) ≤ 1 for all 𝑥</p><ul><li>Probabilities of each outcome should be between 0 and 1</li></ul></li><li><p>∑𝑥 pₓ(x) = 1</p><ul><li>Probabilities of all outcomes added should total up to 1</li></ul></li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | <p>no pmf as continuous variables are a range.<br>- 5.000 and 5.0001 seconds may have different results, and this may cause infinitely many tiny values<br>- thus we have pdf</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | <p>PDF (Probability Density Function)</p><p></p><ul><li>Likelihood range of probability</li><li>Integrate PDF over a range to find actual probability</li><li>Area under curve = probability</li></ul><p></p><p>Properties</p><ul><li><p>f(x) ≥ 0 for all x</p><ul><li>No negative probabilities</li></ul></li><li><p>Integration between inf and -inf of f(x)dx=1</p><ul><li>total area under the curve = 1</li><li>Because sum of all probabilities should be equal 1</li></ul></li><li>P(a ≤ X ≤ b) = ∫ from a to b of f(x) dx</li><li><p>P(X = a) = 0</p><ul><li>Because it is continuous, so there is no way there is an exact probability for outcome a (x=a)</li></ul></li></ul><div><figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FPVk0b59EGb7MvY3PZtzI%2Fimage.png?alt=media&#x26;token=39eff33c-f8a4-4574-bbc8-e20fbbb71931" alt=""><figcaption></figcaption></figure></div> |
| <p>CDF (Cumulative Distribution Function)</p><ul><li>Chance of the value and less</li><li>F(x) = P(X ≤ x)</li><li><p>P(X ≤ x) </p><ul><li>= P(X=x) + P(X< x)  </li><li><p>= 0 + P(X \<x) = P(X\<x)</p><p></p></li></ul></li></ul><p>Complement Rule:<br>P(X ≥ x) = 1 - F(x)</p><p></p><p>Properties</p><ul><li><p>𝐹 is non-decreasing (F(a) ≤ F(b) if a ≤ b)</p><ul><li>CDF value never goes down, because the value is a summation</li></ul></li><li><p>0 ≤ F(a) ≤ 1 for any value a</p><ul><li>Value of CDF is always between 0 and 1</li></ul></li><li><p>lim(a) -> -inf F(a) =0</p><ul><li><p>Probability gets closer to 0 as you go far left, because you're before any possible outcomes</p><ul><li>Which means should always start at 0 for 0.</li></ul></li></ul></li><li><p>lim(a) -> inf F(a) =1</p><ul><li>Probability gets closer to 1 as you go far right, because you passed all possible outcomes</li></ul></li><li><p>P(a < X ≤ b) = F(b) − F(a)</p><ul><li>The probability that X is <strong>between a and b (not including a, but including b)</strong> is the difference between the CDF at b and the CDF at a.</li></ul></li></ul><p></p><ul><li>There is no requirement for cdf to be smooth at all.</li></ul><p></p><ul><li>Jumps/Stepwise</li></ul> | <p>CDF (Cumulative Distribution Function)<br></p><p>Properties</p><ul><li>Same as discrete cdf</li></ul><p></p><p></p><div><figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FHQT4t5V9fdmNuyXNyvWx%2Fimage.png?alt=media&#x26;token=fc7080f5-ad1c-400f-9755-6261d39e63ab" alt=""><figcaption></figcaption></figure></div><p></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p>Given PDF ⇒ f(x),<br>CDF ⇒ integration f(x), from -inf to x<br><br>meaning: F(t) dt<br>- Integral of a function over an interval gives the <strong>area under the curve</strong> of that function between two points ⇒ hence = 1<br>- Calculates area under curve from -inf to x</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <- Same                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p>Given CDF  ⇒ F(x)<br><br>PDF = d F(x) / dx<br>⇒ Derivative of CDF<br><br>meaning:<br>- PDF is the slope of CDF curve<br>- flat CDF ⇒ PDF is 0<br>- steep CDF ⇒ PDF is high.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | <- Same                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

### Expected Value & Variance

Expected Value

* Long run average outcome
  * What number do we get on average if we run the same test over and over again.
* Can also be considered the mean, probability weighted average, or central tendency.

Discrete Variables

* Calculation of it:

$$
E\[X] = \sum\_{} x \* p\_{x} (x) = \mu
$$

* Each x value and their probability, multiplied and added up
* For E\[X] of a function:
  * result of function g(x) \* probability of that function

$$
\text {For E\[X] of a function} = \sum *{x} g(x) \* p*{x} (x)
$$

Continuous Variable

* Calculation:

$$
E\[X] = \int \_{-\infty}^{\infty} x \* fx(x) dx
$$

* For E\[X] of a function:

$$
E\[X] = \int *{-\infty}^{\infty} g(x) \* f*{x}(x) dx
$$

Properties of E\[X]

* These properties apply to all random variables,  \
  including discrete and continuous.

| Properties of E\[X]                  |
| ------------------------------------ |
| 𝐸\[𝑋 + 𝑌] = 𝐸\[𝑋]+ 𝐸\[𝑌]&#xD; |
| 𝐸\[𝑋 − 𝑌]= 𝐸\[𝑋] − 𝐸\[𝑌]&#xD; |
| 𝐸\[𝑎𝑋 + 𝑏] = 𝑎𝐸\[𝑋] + 𝑏      |

Variance and Standard Deviation

* Variance - how spread out the data is, in terms of square distances from the mean
* Standard deviation - square root of variance (original scale)

⇒ So, both tells the same story, in different units.

Calculation

$$
Var(X) = E\[(X-\mu)^2] = E\[X^2] - \mu^2
$$

$$
\text{Standard Deviation}= \sqrt {Var(X)}
$$

Properties of variance

| Properties of Var(X)                   |
| -------------------------------------- |
| <p>Var 𝑎𝑋 + 𝑏 = 𝑎^2Var(𝑋).</p><p> |

</p>                                               |
| <p>If 𝑋, 𝑌 are independent, then<br>Var 𝑋 + 𝑌 = Var 𝑋 − 𝑌 = Var 𝑋 + Var 𝑌 .</p> |

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FtK2gPVbf5BpXC2mJE2Tn%2Fimage.png?alt=media&#x26;token=425a5662-fe5f-4bf9-bd5c-bdbdbf304fe1" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

## 𝜇 is a constant, so 𝐸 \[𝜇^2] = μ^2

{% endhint %}
