> For the complete documentation index, see [llms.txt](https://tethra.gitbook.io/syte/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tethra.gitbook.io/syte/2025/y1.2/one-zero-five/105-cheat-sheet-2.md).

# 105 cheat sheet 2

wk 5 - wk 12

Benouli

* You either get success or failure
* X \~ Bernoulli (p) / Ber (p)
  * \~ stands for follow
* P cannot be = 0 and 1
  * Because 0/1 are never possible solutions
* Related Formulas

$$
Mean (\mu): E\[X] = p
$$

$$
Variance (\sigma^2) : Var(X) = E\[X^2] - \mu^2 = P (1-p)
$$

Binomial

* A series of independent trials where you observe the number of success
  * Independent trials are like flipping a balanced coin for multiple times to observer whether a heads or tails is obtained.
    * As each flip's result is not linked or related to the previous or future flip's results, thus this is called independent trials
* X \~ Binomial (n,p) or X \~ Bin (n,p)
  * \~ stands for follow
*
* Related Formulas

$$
P (X=x) = {n\choose k} p^k (1-p)^{(n-k)}
$$

$$
Mean : E\[X] = np
$$

$$
Variance (\sigma^2): Var(X) = np(1-p)
$$

Geometric

* Total number of trials not fixed, observing for first success after *n* trials
  * All trials need to be independent
* X \~ Geometric (p) / Geo (p)
  * \~ stands for follow
* Related Formulas

$$
P (X =x) = (1-p)^{x-1} p
$$

* where p =  success and (1-p)^ (x-1) = failure&#x20;

$$
Mean (\mu) = E\[X] = \frac{1}{p}
$$

$$
Variance (\sigma^2) = Var (X) = \frac{1-p}{p^2}
$$

$$
Standard Deviation ( \sigma) = \sqrt \frac{1-p} {p^2}
$$

* Memoryless property

$$
Cumulative Probability : P (X \geq x) = (1-p)^{k-1}
$$

Uniform Probability

* X\~ Uniform (a,b) / Unif (a,b)
* Related Formulas

$$
Mean (\mu) = E\[X] = \frac{a+b}{2}
$$

$$
Variance (\sigma^2) = Var (X) = \frac{1}{12} (b-a)^2 = E\[X^2] - \mu^2 =  \int\_{a}^{b} x^2 ,f(x)
$$

Normal/Gaussian Probability

* X \~ Normal (μ,σ^2) or N(μ,σ^2)
* Range from (-∞,∞)
* Related Formula

$$
\text {Standardisation }  (Z) = \frac {X- \mu}{\sigma}
$$

$$
\text {Top p cutoff} : P(Z \geq z) = p
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Fknl5Ggyzwx7cH4XQdBNq%2Fimage.png?alt=media&amp;token=ece7e766-97e0-4cfc-b649-7365b0392d61" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FsFOEYyx8Z0grjV7bAnh5%2Fimage.png?alt=media&amp;token=a39eaf2a-fca1-4ca8-b3d7-51bef17f90e2" alt=""><figcaption></figcaption></figure>

### Joint Probability Mass Function

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F5K4xL0FZt6fQI1WP6iX4%2Fimage.png?alt=media&amp;token=bb84af91-ab29-485c-86c8-3dbbc80559fe" alt=""><figcaption></figcaption></figure>

* Related Formulas

$$
\text {Marginal Probability} : P(Y\_1) = \sum \_{y2}{y2} P(Y\_1,Y\_2)
$$

$$
\text {Calculating the table : } \frac {{n\_1 \choose y\_1}{n\_2 \choose y\_2}{x-n\_1-n\_2 \choose x - (y\_1 +y\_2)}}{total \choose x}
$$

$$
\text {Conditional Probability} : P(Y\_1|Y\_2) = \frac {P(Y\_1, Y\_2)}{P(Y\_2)}
$$

### Variance

* Determines how spread out the values are&#x20;
* Related Formula

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

* Properties of Variance:
  * Constants dont really make a difference, as you can see

$$
Var(aX + b) = a^2 Var(X)
$$

* If X and Y are independent,

$$
Var(X+Y) = Var (X-Y) = Var (X) + Var(Y)
$$

### Covariance and Independence

* Covariance
  * How two things change together
* Covariance Properties

$$
Cov(X,X) = Var(X)
$$

$$
Cov(X,Y) = E\[XY] - \mu\_X \mu\_Y
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FtJ0H9AMBOoyyhI9ewgTM%2Fimage.png?alt=media&amp;token=9c4ded15-595c-47af-b53b-9cf934d4dcbf" alt=""><figcaption></figcaption></figure>

$$
Cov(X+Y,Z) = Cov(X,Z) + Cov(Y,Z)
$$

$$
Cov(aX+b, cY+d) = acCov(X,Y)
$$

$$
Var(X+Y) = Var(X) + Var(Y) + 2Cov(X,Y)
$$

* Related Formulas

$$
Cov (Y\_1, Y\_2) = \rho \* \sqrt {Var (Y\_1)} \* \sqrt {Var(Y\_2)}
$$

$$
Cov(Y\_1, Y\_2) = E\[Y\_1Y\_2] - \mu{Y\_1} \mu{Y\_2} = E\[Y\_1Y\_2] - E\[Y\_1]\[Y\_2]
$$

$$
Cov(X,Y) = E\[(X-\mu\_X)(Y-\mu \_Y)]
$$

$$
E\[Y\_1Y\_2] = \sum p(y\_1,y\_2) \* (y\_1,y\_2)
$$

$$
\rho =  \frac {Cov(Y\_1,Y\_2)}{\sigma *{Y\_1} \* \sigma*{Y\_2}}{}
$$

The above formulas can exist due to this:

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

* If Cov(Y1,Y2) = 0, then variables may be independent
  * Independence implies zero covariance, but Covariance being 0 does not mean independent
* The largest ρ is 1, and the smallest ρ is -1

Regression

* **Regression** is a type of **supervised learning** (trained on labeled data) algorithm used in statistics and machine learning to model the relationship between a **dependent variable** (also called the **target** or **response**) and one or more **independent variables** (also called **predictors** or **features**). The goal of regression is to predict the value of the dependent variable based on the independent variables.
* Predicts continuous outcomes, unlike classification, which is used for predicting discrete labels

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FtEGQzVxCQzrI9a04De8r%2Fimage.png?alt=media&amp;token=d1d610b9-1399-4817-a060-b65301eb3a3d" alt=""><figcaption></figcaption></figure>

* Least Squares Estimators

$$
S\_{xx} = (x -\bar x)^2 = \sum x^2 - \frac {1}{n} ( \sum x)^2
$$

$$
S\_{xy} = (x- \bar x) (y- \bar y) = \sum xy - \frac{1}{n} \sum x \sum y
$$

$$
\text {Slope : } B\_1 = \frac {S\_{xy}}{S\_{xx}} =\frac { \sum xy -  n \bar x \bar y}{\sum x^2 -n \bar x^2}
$$

$$
\text {Constant : } B\_0 = {\bar y} - B\_1  \bar x
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FHtbxA3Qlc8Zjad3kigh6%2Fimage.png?alt=media&amp;token=f1fc63ce-3acc-4d4f-8687-a71cb01b3890" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Ff1UCvfxxUaUqlc5rpVJt%2Fimage.png?alt=media&amp;token=2b6d3de7-fced-4f53-9a8c-b08ecf39332e" alt=""><figcaption></figcaption></figure>

Residual SSR

* How far the predicted values are from actual values
* Smaller SSR means that your predictions are closer to actual values
* If guesses are close, R^2 is high. This means that the model can explain more of the pattern in the data.
  * R^2 = 1 means that the model is perfect.
* Related Formula
  * R is called coefficient of determination

$$
\text {SSR} = 1- r^2 =  \sum ^n\_{i=1} (y- \bar y) ^2
$$

$$
r^2 = 1- \frac {SSR}{S\_{yy}} = \frac{S^2xy}{S\_{xx}S\_{yy}}
$$

MAE & RMSE

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FqEENdffCEedLak7OcKpU%2Fimage.png?alt=media&amp;token=10807f34-6e63-4306-b619-48f12c76d9fd" alt=""><figcaption></figcaption></figure>

RMSE

RMSE is another common metric used to evaluate the difference between values predicted by a model and the actual values.&#x20;

It gives more weight to larger errors than MAE because the errors are squared before averaging.

**Interpretation:**

* **RMSE gives a measure of how spread out the residuals (errors) are**. Since the errors are squared, RMSE is **more sensitive to large errors** compared to MAE. Large differences between predicted and actual values will result in a significantly larger RMSE.
* **Lower RMSE values** indicate better model performance.
* RMSE is commonly used when large errors are particularly undesirable and should be penalized more.

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FrFvpLtGGnAfJ9hPsxMXz%2Fimage.png?alt=media&amp;token=d664b93f-0386-401f-aa1e-6b26414cee4f" alt=""><figcaption></figcaption></figure>

MAE

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F6Z7exzHCkh1aYa59oExP%2Fimage.png?alt=media&amp;token=70871b83-19df-4416-8ef4-1b7bb3a3e027" alt=""><figcaption></figcaption></figure>

**Interpretation:**

* MAE gives a straightforward understanding of the error in the model, as it shows the average absolute difference between actual and predicted values.
* **Lower MAE values** indicate better model performance.
* MAE is not sensitive to outliers (since it only considers absolute differences), meaning that large errors do not disproportionately influence the result.

Statistical Inference

* About using data to make conclusions about the unknown

* There are two kinds:<br>
  * Bayesian inference
    * Combines:
      * A prior belief about a parameter
      * The likelihood of observing a data
    * To produce a posterior (updated belief)<br>
  * Frequentist inference
    * The [truth of a parameter](#user-content-fn-1)[^1] is fixed in the given scenario, but unknown to us
    * Through FI, we are trying to use data to estimate and test assumptions about the fixed value.

Bayesian inference

$$
P(H|E) = \frac {P(E|H) P(H)}{P(E)}
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FEK172SsjzCcLGr6tU2kj%2Fimage.png?alt=media&amp;token=f30a6efe-a7da-4ef6-ae81-73f0065b3717" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FvfXM0UoTdjTRzClUjl4u%2Fimage.png?alt=media&amp;token=32c0512e-88f1-42c4-9e0e-9ab4712f2fea" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FElQLBx7H86QwLQwE8bcz%2Fimage.png?alt=media&amp;token=62da7f32-57f1-4ce4-9f68-e8fbbd04c590" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FFIfjJD1lpmYkC9ZljJpy%2Fimage.png?alt=media&amp;token=bf7cdf71-81ef-4d8e-a1c3-8995e50cf3d3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FWvcKiiOp30i172UPHBjt%2Fimage.png?alt=media&amp;token=c321d88a-c1f7-4070-9aba-31dfeb606eb0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FldcvRLRO0sFV7wlSqOyN%2Fimage.png?alt=media&amp;token=321d7cab-160d-42b0-a29e-8997fbc1626d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FoJYWbArXfwFtp3ep40wb%2Fimage.png?alt=media&amp;token=1e7a7a12-7d83-4264-8b88-4f3139ce0227" alt=""><figcaption></figcaption></figure>

Same posterior, same bayes numerator

* Not same numerator, same posterior
* Because **posterior = numerator / evidence**, even if the **numerator** is the same in two scenarios, if the total of all Bates numerator is different, then the **posterior** will be different.

Conditional Independence

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FZ1kCVD80rkdu99u4tJjO%2Fimage.png?alt=media&amp;token=84866ce7-a3e6-458e-9b4a-eaa8cd4f2cf1" alt=""><figcaption></figcaption></figure>

Updating two data points

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F4lsliX4dtF9xX5fW5ERv%2Fimage.png?alt=media&amp;token=364855f7-84e8-45d0-a831-fee540751861" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FAmclcIIdSp1DAPZ8XhGD%2Fimage.png?alt=media&amp;token=ad43e91f-3c2f-4c52-9bcc-e651f2a20481" alt=""><figcaption></figcaption></figure>

Integration

$$
\frac {x^{n+1} }{n+1}
$$

Differentiation

$$
{n}x^{n-1}
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FjnHUIvKAYN8ZHwVoLJKw%2Fimage.png?alt=media&amp;token=af0778fc-bc65-479c-a834-102a5ebe56b7" alt=""><figcaption></figcaption></figure>

Frequentist Inference

3 ways, but not covering significance testing

* &#x20;\[Estimates an exact value] Maximum Likelihood Estimation

* &#x20;\[Estimates a range of values] Confidence interval

* Significance Testing

* Maximum Likelihood Estimation
  * Used to find the most likely value of a parameter, given the data
  * Kind of like an average, and is the best estimate for the true parameter.
  * To solve, maximize p(x|p) or maximize ln p(x|p)

$$
\theta^\* = \text {arg max }p(x|p = \theta) = \text {arg max ln }p(x|p = \theta)
$$

{% hint style="success" %}
If there are multiple data points, it will be:\
\
*p(x1, x2,x3... | p)    or  p(x1 |p)p(x2 |p)p(x3|p)*&#x20;
{% endhint %}

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FENdZXYUr22jRa2O4ySgC%2Fimage.png?alt=media&amp;token=f72f222d-8591-432b-9cb5-3fff2fabc737" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FtSXPQNgsCStnDpRouP9h%2Fimage.png?alt=media&amp;token=2bd8ddfd-9abf-485b-aa97-db1293ab7a7e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FbYMSHtj8dKERbFGKaUk5%2Fimage.png?alt=media&amp;token=50118fab-3a7e-40c1-a2d1-70cfcaff4f94" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FUo9v0gNefMdj7MuG3A6K%2Fimage.png?alt=media&amp;token=85f9eaa9-f91d-4452-9794-f8b55dbe676f" alt=""><figcaption></figcaption></figure>

Steps:

1. Find log likelihood
2. Find stationary point

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FKVcjbbeqbeB0EgYVYwLc%2Fimage.png?alt=media&amp;token=1c21f40b-25ce-4946-be86-fe0d80060339" alt=""><figcaption></figcaption></figure>

* Confidence Interval
  * Range of values that we believe the true value of the parameter lies, given the data
  * This tells you how precise your estimate is and gives a range of plausible values for the true average.
    * Ie. After a CI test, you are 95% confident that the average weight loss is between x-y value, because if we repeated the experiment 100 times, 95 of the tests would be in this range.

{% hint style="danger" %}
CI does not mean 95% of people lost between x-y value weight.

CI focuses more on the uncertainty of the true value and CI provides a way to confirm the range where the true value of the population mean could be, rather than where the each individual people's data fall.\
\
CI is about the confidence percentage around estimating the **true population mean (**&#x72;eflects the reliability of the **estimation method** **),**&#x6E;ot the probability that the **specific interval** from one sample contains the true mean.

{% endhint %}

$$
P(\theta\_{L} \leq \theta \leq \theta\_{U})= 1 - \alpha
$$

&#x20;                                                      where 1-a is the coefficient/confidence level.

* CI for normal data with known variance

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FSYkIKhsqJ6aqUE7J31BI%2Fimage.png?alt=media&amp;token=041e353e-484f-478d-8260-1d1516a349d3" alt=""><figcaption></figcaption></figure>

* CI for normal data with unknown variance

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FDOSq21Ut2neLqJqY4u1X%2Fimage.png?alt=media&amp;token=12c96c5b-a231-4d84-869b-ffa90cb17863" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FnYMrFZaD69MCS3nzm9J5%2Fimage.png?alt=media&amp;token=120fcde8-f0aa-4355-8990-75adc1b42004" alt=""><figcaption></figcaption></figure>

* Follows a *t*-distribution
  * You’re trying to estimate the **true average** of something (like how much weight people lose after running every day for 3 months). Since you don’t have all the data from everyone, you have to **make a guess**.&#x20;
  * The **t-distribution** helps you make that guess, but **it knows your sample’s small**, so it’s a little extra careful.&#x20;
  * The **degrees of freedom (df)** tell you how much you can trust your guess — the bigger the df, the more you can trust it.
    * When df -> infinity, it becomes a standard normal

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Fq3YL1uaWS14tHiv0Nn5O%2Fimage.png?alt=media&amp;token=07c91249-ba4c-4856-abc5-52a725e52546" alt=""><figcaption></figcaption></figure>

Classification

* Response is categorical
* Supervised, as we randomly split into training and testing data <br>

Naive Bayes&#x20;

* **Probabilistic classifier** based on **Bayes' Theorem**. It’s used to classify data based on the likelihood of certain features or attributes, under the assumption that these features are **independent** of each other (feature independence)

To classify a sample, we calculate:

$$
P(y∣features)∝P(y)× ∏\_i
P(x\_i ∣y)
$$

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F2HmEjfUfK8JqpwKJRf9W%2Fimage.png?alt=media&amp;token=8cfaac3c-462a-4dbf-a54d-b93225a15b05" alt=""><figcaption></figcaption></figure>

* P(y) ⇒ Prior probability of y
* Summation ⇒ Likelihood of each feature x given y

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FNIcvP9QDXiHsHteh9g33%2Fimage.png?alt=media&amp;token=61c2d0c5-180c-4378-bace-c3d7ed5e9eb8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FMcUU0dbXD9uViTvA8nCq%2Fimage.png?alt=media&amp;token=00bec62c-896e-4a08-a80a-f0bf82cfec76" alt=""><figcaption><p>exp is exponent</p></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FZfkSR6VuNPpYKgPAhZdE%2Fimage.png?alt=media&amp;token=f3170b8f-5958-47a3-9da3-0fb8760715a3" alt=""><figcaption></figcaption></figure>

Step 1: Estimate the Prior probability using CHD&#x20;

Step 2: Estimate Likelihood for categorical features against each variable column

* To find likelihood of features, use MLE.
  * Binomial - Categorical
  * Normal - Numerical

Step 3: Estimate Likelihood for numeric features

Step 4: Calculate Bayes Numerators

Step 5: Make Prediction

{% hint style="warning" %}
If any of the likelihood is 0, then the final score will be 0, meaning that it can unfairly eliminate a class due to a zero probability from limited data.

\
Hence, to solve this, people use smoothing (ie. Laplace smoothing), which prevents probability from being exactly 0.
{% endhint %}

Laplace smoothing

* Adds one to all non numerical data variables
  * Pretends that every possibility has happened at least once, and makes model more realistic
  * Probabilities are now non-zero

\*watch out joint likelihood (see below)

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Faxb8GLphPE8Kd96zWSZE%2Fimage.png?alt=media&amp;token=5ed0f3a8-4866-402f-9751-2ab1d3c6ee44" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FWcMvijKRLs1CpkJKmQft%2Fimage.png?alt=media&amp;token=93ae89f7-bdf8-4992-a120-eb9cd4c25359" alt=""><figcaption></figcaption></figure>

Evaluation Metrics

<table><thead><tr><th width="173.20001220703125">Type</th><th>Methods</th></tr></thead><tbody><tr><td>Classification</td><td><ul><li><p>Accuracy =  <span class="math">\frac{ \text{No of correct predictions}}{\text{No of total predictions}}</span></p><ul><li>Or, TP+TN/(TP+TN+FP+FN)</li><li>To be used in balanced datasets</li></ul></li><li><p>Precision = TP/(TP+FP)</p><ul><li>High precision means few false positives</li><li>Good when false positives are costly</li></ul></li><li><p>Recall = TP/TP+FN</p><ul><li>High recall = few false negatives</li><li>Good when missing a positive is costly</li></ul></li><li><p>F1-score = 2* (Precision) * (Recall) / (Precision + Recall)</p><ul><li>Combination of precision and recall</li><li>Balances both FP and FN</li></ul></li></ul></td></tr><tr><td>Regression</td><td><p>Measures the difference between the true and predicted set</p><ul><li>RMSE</li><li>MAE</li></ul></td></tr></tbody></table>

* Clustering vs Regression
  * Response variable ⇒ output
    * In **classification**, the response variable is **categorical** (e.g., "spam" or "not spam").
    * In **regression**, the response variable is **continuous** (e.g., predicting house prices).
  * Predictor variable ⇒ Variables that you feed into model to gain response
    * Classification and regression same
  * Eval metrics ⇒ Refer to above.

4 Outcomes

* **True Positives (TP)**: The model correctly predicts the positive class (predicted positive, actual positive).
* **True Negatives (TN)**: The model correctly predicts the negative class (predicted negative, actual negative).
* **False Positives (FP)**: The model incorrectly predicts the positive class (predicted positive, actual negative) — this is also known as a **Type I error**.
  * Model overestimates number of positives
  * Healthy patient is predicted to have a disease.
* **False Negatives (FN)**: The model incorrectly predicts the negative class (predicted negative, actual positive) — this is also known as a **Type II error**.
  * Model underestimates  umber of positives/miss a positive case
    * Sick patient is predicted to be healthy

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F4voxq701W9G9VqtFFIJn%2Fimage.png?alt=media&amp;token=941a4945-4ce0-4150-99d1-c499bd2dfa85" alt=""><figcaption></figcaption></figure>

Clustering&#x20;

* Unsupervised learning based on predefined classes

K-means clustering

* Good for well separated clusters, where each point belongs to one and ONLY one clusters (a concept called hard clusters)
  * Hard clusters ⇒ Each cluster is deterministic, non-probabilistic
* However, real-world data may overlap each other, causing cluster assignment to have high uncertainty for points in between clusters (soft clusters)
  * The uncertainty cannot be modelled.
  * Soft clusters ⇒ Each point has a probability in each cluster, and is a mixture of clusters.

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FatCBrY8XpSXnd4nWwCUI%2Fimage.png?alt=media&amp;token=ec19967d-afbe-4191-873a-ce3579b3c601" alt=""><figcaption><p>Iteration 1</p></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FkK0hS39O5ZMdSq60ISVR%2Fimage.png?alt=media&amp;token=fc50c69b-6c38-4876-9e56-4af8c7dbea1e" alt=""><figcaption><p>Iteration 2</p></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F2Hz6pQkIphTyakxUdE1s%2Fimage.png?alt=media&amp;token=1944ba6d-5f7d-4b87-b86d-222673273fc1" alt=""><figcaption><p>Iteration 3</p></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Fz67O5flPxmWrOxJywLaJ%2Fimage.png?alt=media&amp;token=4f1bff06-96d2-451f-9866-636697091e08" alt=""><figcaption><p>Iteration 4</p></figcaption></figure>

Example

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Fi6DNFv8T1G9Ff1rbnPPA%2Fimage.png?alt=media&amp;token=9a5dab5d-e527-46b0-855f-07853246b213" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2Fl5dVUR7q6iZS4FZEiQCi%2Fimage.png?alt=media&amp;token=5bf3f25c-37c8-4225-b6f6-ba8b0ecdc297" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FjLHoqYeQ416y3bsZ0YJi%2Fimage.png?alt=media&amp;token=c31543ff-cfd8-4527-968a-55b1a2f2d486" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F0RDb4d9PKWkpyIMVpfza%2Fimage.png?alt=media&amp;token=8f8e047f-86ab-4bed-98e5-90183d61831e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2F4yWGc5DUZinVgELe7QKe%2Fimage.png?alt=media&amp;token=6a19e1bf-6732-40f0-b03d-834c81a70ecf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FtOli19xBbizwmWOpvv0T%2Fimage.png?alt=media&amp;token=842c8a43-f260-4807-a355-1778122f405f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://482590904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6E9aQQS3hXkCehJiKzTA%2Fuploads%2FbV8LFSZIcezDEBTHlNCo%2Fimage.png?alt=media&amp;token=a00dbea1-879f-45bc-b820-6a33b6d2a43a" alt=""><figcaption></figcaption></figure>

Gaussian mixture models

* Instead of assumes a normal distribution bell curve, GMM has multiple bell curves overlapping&#x20;
* GMMs work well with messy real-world data, considered as universal approximators
  * Universal approximators: Given enough bell curves, it can model any shape of data distribution.
    * Whether it is a nice smooth curve is a different story.
* Soft clusters, hence can handle overlapping clusters.
* Probabilistic, adapts to the shape of the data using variance.

[^1]: ie. Claim of the running parameter: Running every day means that you will lose 20kg after 3 months.<br>

    * By Frequentist inference, we are testing whether the **average weight loss** for people who run every day is 20kg.
    * Essentially, we just assume the claim is already true, but test the consistency of the claim, meaning that the data given to us could realistically happen if claim is true.
