## Practical Data Science - Classroom to Careers


### Session 2

Today we intend to cover the following topics. We shall look at - 
 - What are the areas of application ?
 - What parameters are important when dealing with estimated related to these distributions ?

##### Poisson Distribution
##### Geometric Distribution 
##### Exponential Distribution


Also we shall cover the Basics of Linear Algebra to get some hang of matrix operations and try to visualize how this is helpful in representing an equation

##### Basic Linear Algebra, Matrices  - why linear algebraic view is important??

 - Matrix Addition
 - Matrix Multiplication
 - Transpose of a Matrix
 - Diagonal Matrix
 - Identity Matrix
 - Inverse of a Matrix


##### Poisson Distribution

The Poisson distribution is a discrete probability distribution of the number of events (count of events) occurring in a given time period, given the average number of times the event occurs over that time period. For example, number of users visited a website in a given time interval can be thought of a Poisson process

**Parameters** 

Poisson distribution is described in terms of the rate (mu) at which the events happen

**Note:** This is ONLY applicable for **time-independent** events

**Poisson probability equation**

If X follows a Poisson distribution, then the probability of observing k events over the time period is

**X** Discrete random variable that represents the number of events observed over a given time period

**lambda (λ)** The expected value (average) of X. 



\begin{equation*}
P(X=k) = \frac{\lambda^ke^{-\lambda}}{k!}
\end{equation*}

**Applications**

 - Staffing and Scheduling
 - Finance
 - Disaster Management



```python
from scipy.stats import poisson
import seaborn as sns
import warnings

warnings.filterwarnings(action='ignore')

data_poisson = poisson.rvs(mu=2, size=1000)
ax = sns.distplot(data_poisson,
                  kde=False,
                  color='blue',
                  hist_kws={"linewidth": 15,'alpha':1})
ax.set(xlabel='Poisson prob', ylabel='Frequency / Event Counts')
```

##### Exponential and Geometric Distributions

**Geometric Distribution**

The Geometric distribution is a probability distribution (discrete values) of the number of failures (count of failures) occurring before the first success. For example, probability of k failures in an examination attempt before the success

**Parameters** 

Geometric distribution is described in terms of -

**k** no. of failures

**p** the probability of success

**Geometric probability equation**

\begin{equation*}
P(X=k) = (1-p)^k*p
\end{equation*}

**Exponential Distribution**

The exponential distribution is a continuous probability distribution which describes the amount of time it takes to obtain a success in a series of continuously occurring independent trials. It is a continuous analog of the geometric distribution.



#### Bayes Theorem on Conditional Probability

Bayes Theorem or Bayes Rule describes the probability of an event, given prior knowledge of conditions that might be related to the event

It is mathematically expressed as follows

\begin{equation*}
P(A|B) = \frac{P(B|A)P(A)}{P(B)}
\end{equation*}

**Applications**

 - Association Rule Mining
 - Market Basket Analysis (follows from above)


#### Matrix operations

**Matrix Addition/ Subtraction**

We add matrices/each individual elements of matrices together, which produces another Matrix

$$A = \begin{bmatrix} a11 & a12 & a13 \\ a21 & a22 & a23 \\ a31 & a32 & a33 \end{bmatrix}$$ 

$$B = \begin{bmatrix} b11 & b12 & b13 \\ b21 & b22 & b23 \\ b31 & b32 & b33 \end{bmatrix}$$ 

$$ A + B = \begin{bmatrix} a11+b11 & a12+b12 & a13+b13 \\ a21+b21 & a22+b22 & a23+b23 \\ a31+b31 & a32+b32 & a33+b33 \end{bmatrix}$$ 

Matrix addition follows transitive property

A + (-)B = (-)B + A

**Matrix Multiplication**

***Scalar Product***

We multiply a matrix/each individual elements of a matrix by a scalar, which produces another matrix

If we multiply a matrix A by a scalar k, the result is going to be a new matrix (M), which is nothing but a scaled version of matrix A by a factor of k

M = k.A =  $$M = \begin{bmatrix} k*a11 & k*a12 & k*a13 \\ k*a21 & k*a22 & k*a23 \\ k*a31 & k*a32 & k*a33 \end{bmatrix}$$ 

***Vector Product***

Two Matrices A and B can be multiplies if the following condition is met - **Number of columns in the matrix on the left** should be same as the **Number of rows in the matrix on the right**

The resultant is going to be a Matrix of dimension **(No. of rows in Left Matrix) x (No. of columns in Right Matrix)**

***Determinant of a Square matrix***

The determinant of a square (2x2) matrix is computed as follows -


$$A =   \begin{bmatrix}
    a & b \\
    c & d
  \end{bmatrix}$$
  
$$D = \begin{equation}
    \det{(A)} = (ad - bc) \\
  \end{equation}$$



**Major Application in formulating model equations**

**y1 = w11*x1 + w12*x2 + w13*x3 + w14*x4**

**y2 = w21*x1 + w22*x2 + w23*x3 + w24*x4**

\begin{equation}
  \begin{bmatrix}
    w11 & w12 & w13 & w14 \\
    w21 & w22 & w23 & w24
  \end{bmatrix}
  %
  \begin{bmatrix}
    x1 \\
    x2 \\
    x3 \\
    x4 \\
  \end{bmatrix} 
  %
   = \begin{bmatrix}
    w11*x1 + w12*x2 + w13*x3 +  w14*x4 \\
    w21*x1 + w22*x2 + w23*x3 +  w24*x4 \\
  \end{bmatrix} 
\end{equation}

#### Eigenvalues and Eigen Vectors

An eigenvector is a vector whose direction remains unchanged when a linear transformation is applied to it. 

Consider the image below in which three vectors are shown. The green square is only drawn to illustrate the linear transformation that is applied to each of these three vectors.



image and content courtesy: www.visiondummy.com

When a given **nxn** Matrix is given we will have to identify a vector **v** such that 

  **A**.**v**=λ.**v**  
  
  where - 
  
  **v** is the Eigen Vector of Matrix A
  
  **λ** is the Eigen value corresponding to the eigen vector **v**

***Understanding with an Example***

Compute the Eigen-value(s) and Eigen-vector(s) corresponding to the Matrix A

$$A = \begin{bmatrix} 2 & 3 \\ 2 & 1 \end{bmatrix}$$ 


































```python

```

ed6ff88df0f86d8e8a48a8700743c29e6440c173
ipynb
Jupyter Notebook
Session2_PDS.ipynb
rajivbits/IPython-Notebooks
6ff78b85d18c79d4ca0b7aeb949c89bb1ada8679
BSD-3-Clause
Session2_PDS.ipynb
rajivbits/IPython-Notebooks
6ff78b85d18c79d4ca0b7aeb949c89bb1ada8679
BSD-3-Clause
Session2_PDS.ipynb
rajivbits/IPython-Notebooks
6ff78b85d18c79d4ca0b7aeb949c89bb1ada8679
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES