<a href="https://colab.research.google.com/github/AHartNtkn/AB-Demo/blob/master/module3-dimensionality-reduction/DS7_High_Dimensional_Data_Assignment.ipynb" target="_parent"></a>

# Vertical Line Test

## 1.1 Create two graphs, one that passes the vertical line test and one that does not.


```
import numpy as np
import matplotlib.pyplot as plt
```


```
t = np.arange(-2.0, 2.0, 0.01)
s = t**2
```


```
plt.plot(t, s)
plt.show()
```


```
plt.plot(s, t)
plt.show()
```

## 1.2 Why are graphs that don't pass the vertical line test not considered "functions?"

Well, firstly because the graph of a function is not the same thing as a function itself, so no graph is actually a function. Outside of that, the second graph doesn't graph a function because it maps to multple outputs from a single input.

# Functions as Relations

## 2.1 Which of the following relations are functions? Why?

\begin{align}
\text{Relation 1: } \{(1, 2), (3, 2), (1, 3)\}
\\
\text{Relation 2: } \{(1, 3), (2, 3), (6, 7)\}
\\
\text{Relation 3: } \{(9, 4), (2, 1), (9, 6)\}
\\
\text{Relation 4: } \{(6, 2), (8, 3), (6, 4)\}
\\
\text{Relation 5: } \{(2, 6), (2, 7), (2, 4)\}
\end{align}

If you're defining functions as mappings from inputs to outputs, then NONE of those relations are functions since they aren't mappings; they're sets of ordered-pairs. However, relation 2 can be coerced into a function since each pair's first member is unique among the relation's pairs. (Incidendly, relations 3, 4, and 5 can also be coerced into functions by taking the second of its pairs as the input).

# Functions as a mapping between dimensions


## 3.1 for the following functions what is the dimensionality of the domain (input) and codomain (range/output)?

\begin{align}
m(𝑥_1,𝑥_2,𝑥_3)=(x_1+x_2, x_1+x_3, x_2+x_3)
\\
n(𝑥_1,𝑥_2,𝑥_3,𝑥_4)=(x_2^2 + x_3, x_2x_4)
\end{align}

$m : \mathbb{R}^3 \to \mathbb{R}^3$

$n : \mathbb{R}^4 \to \mathbb{R}^2$

## 3.2 Do you think it's possible to create a function that maps from a lower dimensional space to a higher dimensional space? If so, provide an example.

Yes:

$\text{spiral}(\theta) = (e^{ \theta } \text{sin}(\theta), e^{ \theta } \text{cos}(\theta))$


```
t = np.arange(-200.0, 20.0, 0.01)
tightness = .01
xs = np.e**(tightness*t) * np.sin(t)
ys = np.e**(tightness*t) * np.cos(t)

plt.plot(xs, ys)
plt.show()
```

# Vector Transformations

## 4.1 Plug the corresponding unit vectors into each function. Use the output vectors to create a transformation matrix.

\begin{align}
p(\begin{bmatrix}x_1 \\ x_2 \end{bmatrix}) = \begin{bmatrix} x_1 + 3x_2 \\2 x_2 - x_1 \\  \end{bmatrix}
\\
\\
q(\begin{bmatrix}x_1 \\ x_2 \\ x_3\end{bmatrix}) = \begin{bmatrix} 4x_1 + x_2 + 2x_3 \\2 x_2 - x_1 + 3x_3 \\ 5x_1 - 2x_3 + x_2  \end{bmatrix}
\end{align}


```
def p(x):
  return np.array([x[0] + 3 *x[1],
          2 * x[1] - x[0]])

def q(x):
  return np.array([4 * x[0] + 1 * x[1] + 2 * x[2],
          -1 * x[0] + 2 * x[1] + 3 * x[2],
          5 * x[0] + 1 * x[1] - 2 * x[2]])

print(p(np.array([[1],[0]])))
print(p(np.array([[0],[1]])))

print(q(np.array([[1],[0],[0]])))
print(q(np.array([[0],[1],[0]])))
print(q(np.array([[0],[0],[1]])))
```

    [[ 1]
     [-1]]
    [[3]
     [2]]
    [[ 4]
     [-1]
     [ 5]]
    [[1]
     [2]
     [1]]
    [[ 2]
     [ 3]
     [-2]]



```
ptran = np.array([ p(np.array([[1],[0]])).T[0], p(np.array([[0],[1]])).T[0] ]).T
qtran = np.array([ q(np.array([[1],[0],[0]])).T[0], q(np.array([[0],[1],[0]])).T[0], q(np.array([[0],[0],[1]])).T[0] ]).T

print(ptran, '\n')
print(qtran)
```

    [[ 1  3]
     [-1  2]] 
    
    [[ 4  1  2]
     [-1  2  3]
     [ 5  1 -2]]



```
print(np.matmul(ptran, [[1],[0]]))
print(np.matmul(ptran, [[0],[1]]))

print(np.matmul(qtran, [[1],[0],[0]]))
print(np.matmul(qtran, [[0],[1],[0]]))
print(np.matmul(qtran, [[0],[0],[1]]))
```

    [[ 1]
     [-1]]
    [[3]
     [2]]
    [[ 4]
     [-1]
     [ 5]]
    [[1]
     [2]
     [1]]
    [[ 2]
     [ 3]
     [-2]]


## 4.2 Verify that your transformation matrices are correct by choosing an input matrix and calculating the result both via the traditional functions above and also via vector-matrix multiplication.


```
print(np.matmul(ptran, [[2],[-3]]))
print(p(np.array([[2],[-3]])))

print(np.matmul(qtran, [[4],[-5],[7]]))
print(q(np.array([[4],[-5],[7]])))
```

    [[-7]
     [-8]]
    [[-7]
     [-8]]
    [[25]
     [ 7]
     [ 1]]
    [[25]
     [ 7]
     [ 1]]


# Eigenvalues and Eigenvectors

## 5.1 In your own words, give an explanation for the intuition behind eigenvalues and eigenvectors.

Given some linear transformation, an eigenvector is a vector which is at most scaled by the transformation. The coeficient of this scaling is the eigenvalue. Fiven a transformation $T$, $\lambda$ is an eigenvalue of the eigenvector $v$ of $T$ if and only if $Tv = \lambda v$.

# The Curse of Dimensionality

## 6.1 What are some of the challenges of working with high dimensional spaces?

*   Data becomes hard to visualize as you can't plot as many spacial dimensions as you have.
*   Euclidean distance measures become less useful.



## 6.2 What is the rule of thumb for how many observations you should have compared to parameters in your model?

One should have at least five times more observations as parameters.

# Principal Component Analysis

## 7.1 Load the UCI Machine Learning Repository's [Iris Dataset](https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/d546eaee765268bf2f487608c537c05e22e4b221/iris.csv) and use PCA to isolate the dataset's first and second principal components and plot them on a graph. 


```
import pandas as pd
iris = pd.read_csv('https://gist.githubusercontent.com/curran/a08a1080b88344b0c8a7/raw/d546eaee765268bf2f487608c537c05e22e4b221/iris.csv')
iris.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>sepal_length</th>
      <th>sepal_width</th>
      <th>petal_length</th>
      <th>petal_width</th>
      <th>species</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>5.1</td>
      <td>3.5</td>
      <td>1.4</td>
      <td>0.2</td>
      <td>setosa</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4.9</td>
      <td>3.0</td>
      <td>1.4</td>
      <td>0.2</td>
      <td>setosa</td>
    </tr>
    <tr>
      <th>2</th>
      <td>4.7</td>
      <td>3.2</td>
      <td>1.3</td>
      <td>0.2</td>
      <td>setosa</td>
    </tr>
    <tr>
      <th>3</th>
      <td>4.6</td>
      <td>3.1</td>
      <td>1.5</td>
      <td>0.2</td>
      <td>setosa</td>
    </tr>
    <tr>
      <th>4</th>
      <td>5.0</td>
      <td>3.6</td>
      <td>1.4</td>
      <td>0.2</td>
      <td>setosa</td>
    </tr>
  </tbody>
</table>
</div>




```
from numpy import array
from numpy import mean
from numpy import std
from numpy import cov
from numpy.linalg import eig
```


```
X = array([iris['sepal_length'], iris['sepal_width'], iris['petal_length'], iris['petal_width']]).T
print("Data: ", X)
```

    Data:  [[5.1 3.5 1.4 0.2]
     [4.9 3.  1.4 0.2]
     [4.7 3.2 1.3 0.2]
     [4.6 3.1 1.5 0.2]
     [5.  3.6 1.4 0.2]
     [5.4 3.9 1.7 0.4]
     [4.6 3.4 1.4 0.3]
     [5.  3.4 1.5 0.2]
     [4.4 2.9 1.4 0.2]
     [4.9 3.1 1.5 0.1]
     [5.4 3.7 1.5 0.2]
     [4.8 3.4 1.6 0.2]
     [4.8 3.  1.4 0.1]
     [4.3 3.  1.1 0.1]
     [5.8 4.  1.2 0.2]
     [5.7 4.4 1.5 0.4]
     [5.4 3.9 1.3 0.4]
     [5.1 3.5 1.4 0.3]
     [5.7 3.8 1.7 0.3]
     [5.1 3.8 1.5 0.3]
     [5.4 3.4 1.7 0.2]
     [5.1 3.7 1.5 0.4]
     [4.6 3.6 1.  0.2]
     [5.1 3.3 1.7 0.5]
     [4.8 3.4 1.9 0.2]
     [5.  3.  1.6 0.2]
     [5.  3.4 1.6 0.4]
     [5.2 3.5 1.5 0.2]
     [5.2 3.4 1.4 0.2]
     [4.7 3.2 1.6 0.2]
     [4.8 3.1 1.6 0.2]
     [5.4 3.4 1.5 0.4]
     [5.2 4.1 1.5 0.1]
     [5.5 4.2 1.4 0.2]
     [4.9 3.1 1.5 0.1]
     [5.  3.2 1.2 0.2]
     [5.5 3.5 1.3 0.2]
     [4.9 3.1 1.5 0.1]
     [4.4 3.  1.3 0.2]
     [5.1 3.4 1.5 0.2]
     [5.  3.5 1.3 0.3]
     [4.5 2.3 1.3 0.3]
     [4.4 3.2 1.3 0.2]
     [5.  3.5 1.6 0.6]
     [5.1 3.8 1.9 0.4]
     [4.8 3.  1.4 0.3]
     [5.1 3.8 1.6 0.2]
     [4.6 3.2 1.4 0.2]
     [5.3 3.7 1.5 0.2]
     [5.  3.3 1.4 0.2]
     [7.  3.2 4.7 1.4]
     [6.4 3.2 4.5 1.5]
     [6.9 3.1 4.9 1.5]
     [5.5 2.3 4.  1.3]
     [6.5 2.8 4.6 1.5]
     [5.7 2.8 4.5 1.3]
     [6.3 3.3 4.7 1.6]
     [4.9 2.4 3.3 1. ]
     [6.6 2.9 4.6 1.3]
     [5.2 2.7 3.9 1.4]
     [5.  2.  3.5 1. ]
     [5.9 3.  4.2 1.5]
     [6.  2.2 4.  1. ]
     [6.1 2.9 4.7 1.4]
     [5.6 2.9 3.6 1.3]
     [6.7 3.1 4.4 1.4]
     [5.6 3.  4.5 1.5]
     [5.8 2.7 4.1 1. ]
     [6.2 2.2 4.5 1.5]
     [5.6 2.5 3.9 1.1]
     [5.9 3.2 4.8 1.8]
     [6.1 2.8 4.  1.3]
     [6.3 2.5 4.9 1.5]
     [6.1 2.8 4.7 1.2]
     [6.4 2.9 4.3 1.3]
     [6.6 3.  4.4 1.4]
     [6.8 2.8 4.8 1.4]
     [6.7 3.  5.  1.7]
     [6.  2.9 4.5 1.5]
     [5.7 2.6 3.5 1. ]
     [5.5 2.4 3.8 1.1]
     [5.5 2.4 3.7 1. ]
     [5.8 2.7 3.9 1.2]
     [6.  2.7 5.1 1.6]
     [5.4 3.  4.5 1.5]
     [6.  3.4 4.5 1.6]
     [6.7 3.1 4.7 1.5]
     [6.3 2.3 4.4 1.3]
     [5.6 3.  4.1 1.3]
     [5.5 2.5 4.  1.3]
     [5.5 2.6 4.4 1.2]
     [6.1 3.  4.6 1.4]
     [5.8 2.6 4.  1.2]
     [5.  2.3 3.3 1. ]
     [5.6 2.7 4.2 1.3]
     [5.7 3.  4.2 1.2]
     [5.7 2.9 4.2 1.3]
     [6.2 2.9 4.3 1.3]
     [5.1 2.5 3.  1.1]
     [5.7 2.8 4.1 1.3]
     [6.3 3.3 6.  2.5]
     [5.8 2.7 5.1 1.9]
     [7.1 3.  5.9 2.1]
     [6.3 2.9 5.6 1.8]
     [6.5 3.  5.8 2.2]
     [7.6 3.  6.6 2.1]
     [4.9 2.5 4.5 1.7]
     [7.3 2.9 6.3 1.8]
     [6.7 2.5 5.8 1.8]
     [7.2 3.6 6.1 2.5]
     [6.5 3.2 5.1 2. ]
     [6.4 2.7 5.3 1.9]
     [6.8 3.  5.5 2.1]
     [5.7 2.5 5.  2. ]
     [5.8 2.8 5.1 2.4]
     [6.4 3.2 5.3 2.3]
     [6.5 3.  5.5 1.8]
     [7.7 3.8 6.7 2.2]
     [7.7 2.6 6.9 2.3]
     [6.  2.2 5.  1.5]
     [6.9 3.2 5.7 2.3]
     [5.6 2.8 4.9 2. ]
     [7.7 2.8 6.7 2. ]
     [6.3 2.7 4.9 1.8]
     [6.7 3.3 5.7 2.1]
     [7.2 3.2 6.  1.8]
     [6.2 2.8 4.8 1.8]
     [6.1 3.  4.9 1.8]
     [6.4 2.8 5.6 2.1]
     [7.2 3.  5.8 1.6]
     [7.4 2.8 6.1 1.9]
     [7.9 3.8 6.4 2. ]
     [6.4 2.8 5.6 2.2]
     [6.3 2.8 5.1 1.5]
     [6.1 2.6 5.6 1.4]
     [7.7 3.  6.1 2.3]
     [6.3 3.4 5.6 2.4]
     [6.4 3.1 5.5 1.8]
     [6.  3.  4.8 1.8]
     [6.9 3.1 5.4 2.1]
     [6.7 3.1 5.6 2.4]
     [6.9 3.1 5.1 2.3]
     [5.8 2.7 5.1 1.9]
     [6.8 3.2 5.9 2.3]
     [6.7 3.3 5.7 2.5]
     [6.7 3.  5.2 2.3]
     [6.3 2.5 5.  1.9]
     [6.5 3.  5.2 2. ]
     [6.2 3.4 5.4 2.3]
     [5.9 3.  5.1 1.8]]



```
means = mean(X.T, axis=1)
print("\n Means: \n", means)
```

    
     Means: 
     [5.84333333 3.054      3.75866667 1.19866667]



```
centered_data = X - means
print("\n Centered Data: \n", centered_data)
```

    
     Centered Data: 
     [[-7.43333333e-01  4.46000000e-01 -2.35866667e+00 -9.98666667e-01]
     [-9.43333333e-01 -5.40000000e-02 -2.35866667e+00 -9.98666667e-01]
     [-1.14333333e+00  1.46000000e-01 -2.45866667e+00 -9.98666667e-01]
     [-1.24333333e+00  4.60000000e-02 -2.25866667e+00 -9.98666667e-01]
     [-8.43333333e-01  5.46000000e-01 -2.35866667e+00 -9.98666667e-01]
     [-4.43333333e-01  8.46000000e-01 -2.05866667e+00 -7.98666667e-01]
     [-1.24333333e+00  3.46000000e-01 -2.35866667e+00 -8.98666667e-01]
     [-8.43333333e-01  3.46000000e-01 -2.25866667e+00 -9.98666667e-01]
     [-1.44333333e+00 -1.54000000e-01 -2.35866667e+00 -9.98666667e-01]
     [-9.43333333e-01  4.60000000e-02 -2.25866667e+00 -1.09866667e+00]
     [-4.43333333e-01  6.46000000e-01 -2.25866667e+00 -9.98666667e-01]
     [-1.04333333e+00  3.46000000e-01 -2.15866667e+00 -9.98666667e-01]
     [-1.04333333e+00 -5.40000000e-02 -2.35866667e+00 -1.09866667e+00]
     [-1.54333333e+00 -5.40000000e-02 -2.65866667e+00 -1.09866667e+00]
     [-4.33333333e-02  9.46000000e-01 -2.55866667e+00 -9.98666667e-01]
     [-1.43333333e-01  1.34600000e+00 -2.25866667e+00 -7.98666667e-01]
     [-4.43333333e-01  8.46000000e-01 -2.45866667e+00 -7.98666667e-01]
     [-7.43333333e-01  4.46000000e-01 -2.35866667e+00 -8.98666667e-01]
     [-1.43333333e-01  7.46000000e-01 -2.05866667e+00 -8.98666667e-01]
     [-7.43333333e-01  7.46000000e-01 -2.25866667e+00 -8.98666667e-01]
     [-4.43333333e-01  3.46000000e-01 -2.05866667e+00 -9.98666667e-01]
     [-7.43333333e-01  6.46000000e-01 -2.25866667e+00 -7.98666667e-01]
     [-1.24333333e+00  5.46000000e-01 -2.75866667e+00 -9.98666667e-01]
     [-7.43333333e-01  2.46000000e-01 -2.05866667e+00 -6.98666667e-01]
     [-1.04333333e+00  3.46000000e-01 -1.85866667e+00 -9.98666667e-01]
     [-8.43333333e-01 -5.40000000e-02 -2.15866667e+00 -9.98666667e-01]
     [-8.43333333e-01  3.46000000e-01 -2.15866667e+00 -7.98666667e-01]
     [-6.43333333e-01  4.46000000e-01 -2.25866667e+00 -9.98666667e-01]
     [-6.43333333e-01  3.46000000e-01 -2.35866667e+00 -9.98666667e-01]
     [-1.14333333e+00  1.46000000e-01 -2.15866667e+00 -9.98666667e-01]
     [-1.04333333e+00  4.60000000e-02 -2.15866667e+00 -9.98666667e-01]
     [-4.43333333e-01  3.46000000e-01 -2.25866667e+00 -7.98666667e-01]
     [-6.43333333e-01  1.04600000e+00 -2.25866667e+00 -1.09866667e+00]
     [-3.43333333e-01  1.14600000e+00 -2.35866667e+00 -9.98666667e-01]
     [-9.43333333e-01  4.60000000e-02 -2.25866667e+00 -1.09866667e+00]
     [-8.43333333e-01  1.46000000e-01 -2.55866667e+00 -9.98666667e-01]
     [-3.43333333e-01  4.46000000e-01 -2.45866667e+00 -9.98666667e-01]
     [-9.43333333e-01  4.60000000e-02 -2.25866667e+00 -1.09866667e+00]
     [-1.44333333e+00 -5.40000000e-02 -2.45866667e+00 -9.98666667e-01]
     [-7.43333333e-01  3.46000000e-01 -2.25866667e+00 -9.98666667e-01]
     [-8.43333333e-01  4.46000000e-01 -2.45866667e+00 -8.98666667e-01]
     [-1.34333333e+00 -7.54000000e-01 -2.45866667e+00 -8.98666667e-01]
     [-1.44333333e+00  1.46000000e-01 -2.45866667e+00 -9.98666667e-01]
     [-8.43333333e-01  4.46000000e-01 -2.15866667e+00 -5.98666667e-01]
     [-7.43333333e-01  7.46000000e-01 -1.85866667e+00 -7.98666667e-01]
     [-1.04333333e+00 -5.40000000e-02 -2.35866667e+00 -8.98666667e-01]
     [-7.43333333e-01  7.46000000e-01 -2.15866667e+00 -9.98666667e-01]
     [-1.24333333e+00  1.46000000e-01 -2.35866667e+00 -9.98666667e-01]
     [-5.43333333e-01  6.46000000e-01 -2.25866667e+00 -9.98666667e-01]
     [-8.43333333e-01  2.46000000e-01 -2.35866667e+00 -9.98666667e-01]
     [ 1.15666667e+00  1.46000000e-01  9.41333333e-01  2.01333333e-01]
     [ 5.56666667e-01  1.46000000e-01  7.41333333e-01  3.01333333e-01]
     [ 1.05666667e+00  4.60000000e-02  1.14133333e+00  3.01333333e-01]
     [-3.43333333e-01 -7.54000000e-01  2.41333333e-01  1.01333333e-01]
     [ 6.56666667e-01 -2.54000000e-01  8.41333333e-01  3.01333333e-01]
     [-1.43333333e-01 -2.54000000e-01  7.41333333e-01  1.01333333e-01]
     [ 4.56666667e-01  2.46000000e-01  9.41333333e-01  4.01333333e-01]
     [-9.43333333e-01 -6.54000000e-01 -4.58666667e-01 -1.98666667e-01]
     [ 7.56666667e-01 -1.54000000e-01  8.41333333e-01  1.01333333e-01]
     [-6.43333333e-01 -3.54000000e-01  1.41333333e-01  2.01333333e-01]
     [-8.43333333e-01 -1.05400000e+00 -2.58666667e-01 -1.98666667e-01]
     [ 5.66666667e-02 -5.40000000e-02  4.41333333e-01  3.01333333e-01]
     [ 1.56666667e-01 -8.54000000e-01  2.41333333e-01 -1.98666667e-01]
     [ 2.56666667e-01 -1.54000000e-01  9.41333333e-01  2.01333333e-01]
     [-2.43333333e-01 -1.54000000e-01 -1.58666667e-01  1.01333333e-01]
     [ 8.56666667e-01  4.60000000e-02  6.41333333e-01  2.01333333e-01]
     [-2.43333333e-01 -5.40000000e-02  7.41333333e-01  3.01333333e-01]
     [-4.33333333e-02 -3.54000000e-01  3.41333333e-01 -1.98666667e-01]
     [ 3.56666667e-01 -8.54000000e-01  7.41333333e-01  3.01333333e-01]
     [-2.43333333e-01 -5.54000000e-01  1.41333333e-01 -9.86666667e-02]
     [ 5.66666667e-02  1.46000000e-01  1.04133333e+00  6.01333333e-01]
     [ 2.56666667e-01 -2.54000000e-01  2.41333333e-01  1.01333333e-01]
     [ 4.56666667e-01 -5.54000000e-01  1.14133333e+00  3.01333333e-01]
     [ 2.56666667e-01 -2.54000000e-01  9.41333333e-01  1.33333333e-03]
     [ 5.56666667e-01 -1.54000000e-01  5.41333333e-01  1.01333333e-01]
     [ 7.56666667e-01 -5.40000000e-02  6.41333333e-01  2.01333333e-01]
     [ 9.56666667e-01 -2.54000000e-01  1.04133333e+00  2.01333333e-01]
     [ 8.56666667e-01 -5.40000000e-02  1.24133333e+00  5.01333333e-01]
     [ 1.56666667e-01 -1.54000000e-01  7.41333333e-01  3.01333333e-01]
     [-1.43333333e-01 -4.54000000e-01 -2.58666667e-01 -1.98666667e-01]
     [-3.43333333e-01 -6.54000000e-01  4.13333333e-02 -9.86666667e-02]
     [-3.43333333e-01 -6.54000000e-01 -5.86666667e-02 -1.98666667e-01]
     [-4.33333333e-02 -3.54000000e-01  1.41333333e-01  1.33333333e-03]
     [ 1.56666667e-01 -3.54000000e-01  1.34133333e+00  4.01333333e-01]
     [-4.43333333e-01 -5.40000000e-02  7.41333333e-01  3.01333333e-01]
     [ 1.56666667e-01  3.46000000e-01  7.41333333e-01  4.01333333e-01]
     [ 8.56666667e-01  4.60000000e-02  9.41333333e-01  3.01333333e-01]
     [ 4.56666667e-01 -7.54000000e-01  6.41333333e-01  1.01333333e-01]
     [-2.43333333e-01 -5.40000000e-02  3.41333333e-01  1.01333333e-01]
     [-3.43333333e-01 -5.54000000e-01  2.41333333e-01  1.01333333e-01]
     [-3.43333333e-01 -4.54000000e-01  6.41333333e-01  1.33333333e-03]
     [ 2.56666667e-01 -5.40000000e-02  8.41333333e-01  2.01333333e-01]
     [-4.33333333e-02 -4.54000000e-01  2.41333333e-01  1.33333333e-03]
     [-8.43333333e-01 -7.54000000e-01 -4.58666667e-01 -1.98666667e-01]
     [-2.43333333e-01 -3.54000000e-01  4.41333333e-01  1.01333333e-01]
     [-1.43333333e-01 -5.40000000e-02  4.41333333e-01  1.33333333e-03]
     [-1.43333333e-01 -1.54000000e-01  4.41333333e-01  1.01333333e-01]
     [ 3.56666667e-01 -1.54000000e-01  5.41333333e-01  1.01333333e-01]
     [-7.43333333e-01 -5.54000000e-01 -7.58666667e-01 -9.86666667e-02]
     [-1.43333333e-01 -2.54000000e-01  3.41333333e-01  1.01333333e-01]
     [ 4.56666667e-01  2.46000000e-01  2.24133333e+00  1.30133333e+00]
     [-4.33333333e-02 -3.54000000e-01  1.34133333e+00  7.01333333e-01]
     [ 1.25666667e+00 -5.40000000e-02  2.14133333e+00  9.01333333e-01]
     [ 4.56666667e-01 -1.54000000e-01  1.84133333e+00  6.01333333e-01]
     [ 6.56666667e-01 -5.40000000e-02  2.04133333e+00  1.00133333e+00]
     [ 1.75666667e+00 -5.40000000e-02  2.84133333e+00  9.01333333e-01]
     [-9.43333333e-01 -5.54000000e-01  7.41333333e-01  5.01333333e-01]
     [ 1.45666667e+00 -1.54000000e-01  2.54133333e+00  6.01333333e-01]
     [ 8.56666667e-01 -5.54000000e-01  2.04133333e+00  6.01333333e-01]
     [ 1.35666667e+00  5.46000000e-01  2.34133333e+00  1.30133333e+00]
     [ 6.56666667e-01  1.46000000e-01  1.34133333e+00  8.01333333e-01]
     [ 5.56666667e-01 -3.54000000e-01  1.54133333e+00  7.01333333e-01]
     [ 9.56666667e-01 -5.40000000e-02  1.74133333e+00  9.01333333e-01]
     [-1.43333333e-01 -5.54000000e-01  1.24133333e+00  8.01333333e-01]
     [-4.33333333e-02 -2.54000000e-01  1.34133333e+00  1.20133333e+00]
     [ 5.56666667e-01  1.46000000e-01  1.54133333e+00  1.10133333e+00]
     [ 6.56666667e-01 -5.40000000e-02  1.74133333e+00  6.01333333e-01]
     [ 1.85666667e+00  7.46000000e-01  2.94133333e+00  1.00133333e+00]
     [ 1.85666667e+00 -4.54000000e-01  3.14133333e+00  1.10133333e+00]
     [ 1.56666667e-01 -8.54000000e-01  1.24133333e+00  3.01333333e-01]
     [ 1.05666667e+00  1.46000000e-01  1.94133333e+00  1.10133333e+00]
     [-2.43333333e-01 -2.54000000e-01  1.14133333e+00  8.01333333e-01]
     [ 1.85666667e+00 -2.54000000e-01  2.94133333e+00  8.01333333e-01]
     [ 4.56666667e-01 -3.54000000e-01  1.14133333e+00  6.01333333e-01]
     [ 8.56666667e-01  2.46000000e-01  1.94133333e+00  9.01333333e-01]
     [ 1.35666667e+00  1.46000000e-01  2.24133333e+00  6.01333333e-01]
     [ 3.56666667e-01 -2.54000000e-01  1.04133333e+00  6.01333333e-01]
     [ 2.56666667e-01 -5.40000000e-02  1.14133333e+00  6.01333333e-01]
     [ 5.56666667e-01 -2.54000000e-01  1.84133333e+00  9.01333333e-01]
     [ 1.35666667e+00 -5.40000000e-02  2.04133333e+00  4.01333333e-01]
     [ 1.55666667e+00 -2.54000000e-01  2.34133333e+00  7.01333333e-01]
     [ 2.05666667e+00  7.46000000e-01  2.64133333e+00  8.01333333e-01]
     [ 5.56666667e-01 -2.54000000e-01  1.84133333e+00  1.00133333e+00]
     [ 4.56666667e-01 -2.54000000e-01  1.34133333e+00  3.01333333e-01]
     [ 2.56666667e-01 -4.54000000e-01  1.84133333e+00  2.01333333e-01]
     [ 1.85666667e+00 -5.40000000e-02  2.34133333e+00  1.10133333e+00]
     [ 4.56666667e-01  3.46000000e-01  1.84133333e+00  1.20133333e+00]
     [ 5.56666667e-01  4.60000000e-02  1.74133333e+00  6.01333333e-01]
     [ 1.56666667e-01 -5.40000000e-02  1.04133333e+00  6.01333333e-01]
     [ 1.05666667e+00  4.60000000e-02  1.64133333e+00  9.01333333e-01]
     [ 8.56666667e-01  4.60000000e-02  1.84133333e+00  1.20133333e+00]
     [ 1.05666667e+00  4.60000000e-02  1.34133333e+00  1.10133333e+00]
     [-4.33333333e-02 -3.54000000e-01  1.34133333e+00  7.01333333e-01]
     [ 9.56666667e-01  1.46000000e-01  2.14133333e+00  1.10133333e+00]
     [ 8.56666667e-01  2.46000000e-01  1.94133333e+00  1.30133333e+00]
     [ 8.56666667e-01 -5.40000000e-02  1.44133333e+00  1.10133333e+00]
     [ 4.56666667e-01 -5.54000000e-01  1.24133333e+00  7.01333333e-01]
     [ 6.56666667e-01 -5.40000000e-02  1.44133333e+00  8.01333333e-01]
     [ 3.56666667e-01  3.46000000e-01  1.64133333e+00  1.10133333e+00]
     [ 5.66666667e-02 -5.40000000e-02  1.34133333e+00  6.01333333e-01]]



```
std_devs = std(X.T, axis=1)
standardized_data = centered_data/std_devs
print("\n Standardized Data: \n", standardized_data)
```

    
     Standardized Data: 
     [[-9.00681170e-01  1.03205722e+00 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00 -1.24957601e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.38535265e+00  3.37848329e-01 -1.39813811e+00 -1.31297673e+00]
     [-1.50652052e+00  1.06445364e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  1.26346019e+00 -1.34127240e+00 -1.31297673e+00]
     [-5.37177559e-01  1.95766909e+00 -1.17067529e+00 -1.05003079e+00]
     [-1.50652052e+00  8.00654259e-01 -1.34127240e+00 -1.18150376e+00]
     [-1.02184904e+00  8.00654259e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.74885626e+00 -3.56360566e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-5.37177559e-01  1.49486315e+00 -1.28440670e+00 -1.31297673e+00]
     [-1.26418478e+00  8.00654259e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.26418478e+00 -1.24957601e-01 -1.34127240e+00 -1.44444970e+00]
     [-1.87002413e+00 -1.24957601e-01 -1.51186952e+00 -1.44444970e+00]
     [-5.25060772e-02  2.18907205e+00 -1.45500381e+00 -1.31297673e+00]
     [-1.73673948e-01  3.11468391e+00 -1.28440670e+00 -1.05003079e+00]
     [-5.37177559e-01  1.95766909e+00 -1.39813811e+00 -1.05003079e+00]
     [-9.00681170e-01  1.03205722e+00 -1.34127240e+00 -1.18150376e+00]
     [-1.73673948e-01  1.72626612e+00 -1.17067529e+00 -1.18150376e+00]
     [-9.00681170e-01  1.72626612e+00 -1.28440670e+00 -1.18150376e+00]
     [-5.37177559e-01  8.00654259e-01 -1.17067529e+00 -1.31297673e+00]
     [-9.00681170e-01  1.49486315e+00 -1.28440670e+00 -1.05003079e+00]
     [-1.50652052e+00  1.26346019e+00 -1.56873522e+00 -1.31297673e+00]
     [-9.00681170e-01  5.69251294e-01 -1.17067529e+00 -9.18557817e-01]
     [-1.26418478e+00  8.00654259e-01 -1.05694388e+00 -1.31297673e+00]
     [-1.02184904e+00 -1.24957601e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.02184904e+00  8.00654259e-01 -1.22754100e+00 -1.05003079e+00]
     [-7.79513300e-01  1.03205722e+00 -1.28440670e+00 -1.31297673e+00]
     [-7.79513300e-01  8.00654259e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.38535265e+00  3.37848329e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.26418478e+00  1.06445364e-01 -1.22754100e+00 -1.31297673e+00]
     [-5.37177559e-01  8.00654259e-01 -1.28440670e+00 -1.05003079e+00]
     [-7.79513300e-01  2.42047502e+00 -1.28440670e+00 -1.44444970e+00]
     [-4.16009689e-01  2.65187798e+00 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-1.02184904e+00  3.37848329e-01 -1.45500381e+00 -1.31297673e+00]
     [-4.16009689e-01  1.03205722e+00 -1.39813811e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-1.74885626e+00 -1.24957601e-01 -1.39813811e+00 -1.31297673e+00]
     [-9.00681170e-01  8.00654259e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  1.03205722e+00 -1.39813811e+00 -1.18150376e+00]
     [-1.62768839e+00 -1.74477836e+00 -1.39813811e+00 -1.18150376e+00]
     [-1.74885626e+00  3.37848329e-01 -1.39813811e+00 -1.31297673e+00]
     [-1.02184904e+00  1.03205722e+00 -1.22754100e+00 -7.87084847e-01]
     [-9.00681170e-01  1.72626612e+00 -1.05694388e+00 -1.05003079e+00]
     [-1.26418478e+00 -1.24957601e-01 -1.34127240e+00 -1.18150376e+00]
     [-9.00681170e-01  1.72626612e+00 -1.22754100e+00 -1.31297673e+00]
     [-1.50652052e+00  3.37848329e-01 -1.34127240e+00 -1.31297673e+00]
     [-6.58345429e-01  1.49486315e+00 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  5.69251294e-01 -1.34127240e+00 -1.31297673e+00]
     [ 1.40150837e+00  3.37848329e-01  5.35295827e-01  2.64698913e-01]
     [ 6.74501145e-01  3.37848329e-01  4.21564419e-01  3.96171883e-01]
     [ 1.28034050e+00  1.06445364e-01  6.49027235e-01  3.96171883e-01]
     [-4.16009689e-01 -1.74477836e+00  1.37235899e-01  1.33225943e-01]
     [ 7.95669016e-01 -5.87763531e-01  4.78430123e-01  3.96171883e-01]
     [-1.73673948e-01 -5.87763531e-01  4.21564419e-01  1.33225943e-01]
     [ 5.53333275e-01  5.69251294e-01  5.35295827e-01  5.27644853e-01]
     [-1.14301691e+00 -1.51337539e+00 -2.60824029e-01 -2.61192967e-01]
     [ 9.16836886e-01 -3.56360566e-01  4.78430123e-01  1.33225943e-01]
     [-7.79513300e-01 -8.19166497e-01  8.03701950e-02  2.64698913e-01]
     [-1.02184904e+00 -2.43898725e+00 -1.47092621e-01 -2.61192967e-01]
     [ 6.86617933e-02 -1.24957601e-01  2.50967307e-01  3.96171883e-01]
     [ 1.89829664e-01 -1.97618132e+00  1.37235899e-01 -2.61192967e-01]
     [ 3.10997534e-01 -3.56360566e-01  5.35295827e-01  2.64698913e-01]
     [-2.94841818e-01 -3.56360566e-01 -9.02269170e-02  1.33225943e-01]
     [ 1.03800476e+00  1.06445364e-01  3.64698715e-01  2.64698913e-01]
     [-2.94841818e-01 -1.24957601e-01  4.21564419e-01  3.96171883e-01]
     [-5.25060772e-02 -8.19166497e-01  1.94101603e-01 -2.61192967e-01]
     [ 4.32165405e-01 -1.97618132e+00  4.21564419e-01  3.96171883e-01]
     [-2.94841818e-01 -1.28197243e+00  8.03701950e-02 -1.29719997e-01]
     [ 6.86617933e-02  3.37848329e-01  5.92161531e-01  7.90590793e-01]
     [ 3.10997534e-01 -5.87763531e-01  1.37235899e-01  1.33225943e-01]
     [ 5.53333275e-01 -1.28197243e+00  6.49027235e-01  3.96171883e-01]
     [ 3.10997534e-01 -5.87763531e-01  5.35295827e-01  1.75297293e-03]
     [ 6.74501145e-01 -3.56360566e-01  3.07833011e-01  1.33225943e-01]
     [ 9.16836886e-01 -1.24957601e-01  3.64698715e-01  2.64698913e-01]
     [ 1.15917263e+00 -5.87763531e-01  5.92161531e-01  2.64698913e-01]
     [ 1.03800476e+00 -1.24957601e-01  7.05892939e-01  6.59117823e-01]
     [ 1.89829664e-01 -3.56360566e-01  4.21564419e-01  3.96171883e-01]
     [-1.73673948e-01 -1.05056946e+00 -1.47092621e-01 -2.61192967e-01]
     [-4.16009689e-01 -1.51337539e+00  2.35044910e-02 -1.29719997e-01]
     [-4.16009689e-01 -1.51337539e+00 -3.33612130e-02 -2.61192967e-01]
     [-5.25060772e-02 -8.19166497e-01  8.03701950e-02  1.75297293e-03]
     [ 1.89829664e-01 -8.19166497e-01  7.62758643e-01  5.27644853e-01]
     [-5.37177559e-01 -1.24957601e-01  4.21564419e-01  3.96171883e-01]
     [ 1.89829664e-01  8.00654259e-01  4.21564419e-01  5.27644853e-01]
     [ 1.03800476e+00  1.06445364e-01  5.35295827e-01  3.96171883e-01]
     [ 5.53333275e-01 -1.74477836e+00  3.64698715e-01  1.33225943e-01]
     [-2.94841818e-01 -1.24957601e-01  1.94101603e-01  1.33225943e-01]
     [-4.16009689e-01 -1.28197243e+00  1.37235899e-01  1.33225943e-01]
     [-4.16009689e-01 -1.05056946e+00  3.64698715e-01  1.75297293e-03]
     [ 3.10997534e-01 -1.24957601e-01  4.78430123e-01  2.64698913e-01]
     [-5.25060772e-02 -1.05056946e+00  1.37235899e-01  1.75297293e-03]
     [-1.02184904e+00 -1.74477836e+00 -2.60824029e-01 -2.61192967e-01]
     [-2.94841818e-01 -8.19166497e-01  2.50967307e-01  1.33225943e-01]
     [-1.73673948e-01 -1.24957601e-01  2.50967307e-01  1.75297293e-03]
     [-1.73673948e-01 -3.56360566e-01  2.50967307e-01  1.33225943e-01]
     [ 4.32165405e-01 -3.56360566e-01  3.07833011e-01  1.33225943e-01]
     [-9.00681170e-01 -1.28197243e+00 -4.31421141e-01 -1.29719997e-01]
     [-1.73673948e-01 -5.87763531e-01  1.94101603e-01  1.33225943e-01]
     [ 5.53333275e-01  5.69251294e-01  1.27454998e+00  1.71090158e+00]
     [-5.25060772e-02 -8.19166497e-01  7.62758643e-01  9.22063763e-01]
     [ 1.52267624e+00 -1.24957601e-01  1.21768427e+00  1.18500970e+00]
     [ 5.53333275e-01 -3.56360566e-01  1.04708716e+00  7.90590793e-01]
     [ 7.95669016e-01 -1.24957601e-01  1.16081857e+00  1.31648267e+00]
     [ 2.12851559e+00 -1.24957601e-01  1.61574420e+00  1.18500970e+00]
     [-1.14301691e+00 -1.28197243e+00  4.21564419e-01  6.59117823e-01]
     [ 1.76501198e+00 -3.56360566e-01  1.44514709e+00  7.90590793e-01]
     [ 1.03800476e+00 -1.28197243e+00  1.16081857e+00  7.90590793e-01]
     [ 1.64384411e+00  1.26346019e+00  1.33141568e+00  1.71090158e+00]
     [ 7.95669016e-01  3.37848329e-01  7.62758643e-01  1.05353673e+00]
     [ 6.74501145e-01 -8.19166497e-01  8.76490051e-01  9.22063763e-01]
     [ 1.15917263e+00 -1.24957601e-01  9.90221459e-01  1.18500970e+00]
     [-1.73673948e-01 -1.28197243e+00  7.05892939e-01  1.05353673e+00]
     [-5.25060772e-02 -5.87763531e-01  7.62758643e-01  1.57942861e+00]
     [ 6.74501145e-01  3.37848329e-01  8.76490051e-01  1.44795564e+00]
     [ 7.95669016e-01 -1.24957601e-01  9.90221459e-01  7.90590793e-01]
     [ 2.24968346e+00  1.72626612e+00  1.67260991e+00  1.31648267e+00]
     [ 2.24968346e+00 -1.05056946e+00  1.78634131e+00  1.44795564e+00]
     [ 1.89829664e-01 -1.97618132e+00  7.05892939e-01  3.96171883e-01]
     [ 1.28034050e+00  3.37848329e-01  1.10395287e+00  1.44795564e+00]
     [-2.94841818e-01 -5.87763531e-01  6.49027235e-01  1.05353673e+00]
     [ 2.24968346e+00 -5.87763531e-01  1.67260991e+00  1.05353673e+00]
     [ 5.53333275e-01 -8.19166497e-01  6.49027235e-01  7.90590793e-01]
     [ 1.03800476e+00  5.69251294e-01  1.10395287e+00  1.18500970e+00]
     [ 1.64384411e+00  3.37848329e-01  1.27454998e+00  7.90590793e-01]
     [ 4.32165405e-01 -5.87763531e-01  5.92161531e-01  7.90590793e-01]
     [ 3.10997534e-01 -1.24957601e-01  6.49027235e-01  7.90590793e-01]
     [ 6.74501145e-01 -5.87763531e-01  1.04708716e+00  1.18500970e+00]
     [ 1.64384411e+00 -1.24957601e-01  1.16081857e+00  5.27644853e-01]
     [ 1.88617985e+00 -5.87763531e-01  1.33141568e+00  9.22063763e-01]
     [ 2.49201920e+00  1.72626612e+00  1.50201279e+00  1.05353673e+00]
     [ 6.74501145e-01 -5.87763531e-01  1.04708716e+00  1.31648267e+00]
     [ 5.53333275e-01 -5.87763531e-01  7.62758643e-01  3.96171883e-01]
     [ 3.10997534e-01 -1.05056946e+00  1.04708716e+00  2.64698913e-01]
     [ 2.24968346e+00 -1.24957601e-01  1.33141568e+00  1.44795564e+00]
     [ 5.53333275e-01  8.00654259e-01  1.04708716e+00  1.57942861e+00]
     [ 6.74501145e-01  1.06445364e-01  9.90221459e-01  7.90590793e-01]
     [ 1.89829664e-01 -1.24957601e-01  5.92161531e-01  7.90590793e-01]
     [ 1.28034050e+00  1.06445364e-01  9.33355755e-01  1.18500970e+00]
     [ 1.03800476e+00  1.06445364e-01  1.04708716e+00  1.57942861e+00]
     [ 1.28034050e+00  1.06445364e-01  7.62758643e-01  1.44795564e+00]
     [-5.25060772e-02 -8.19166497e-01  7.62758643e-01  9.22063763e-01]
     [ 1.15917263e+00  3.37848329e-01  1.21768427e+00  1.44795564e+00]
     [ 1.03800476e+00  5.69251294e-01  1.10395287e+00  1.71090158e+00]
     [ 1.03800476e+00 -1.24957601e-01  8.19624347e-01  1.44795564e+00]
     [ 5.53333275e-01 -1.28197243e+00  7.05892939e-01  9.22063763e-01]
     [ 7.95669016e-01 -1.24957601e-01  8.19624347e-01  1.05353673e+00]
     [ 4.32165405e-01  8.00654259e-01  9.33355755e-01  1.44795564e+00]
     [ 6.86617933e-02 -1.24957601e-01  7.62758643e-01  7.90590793e-01]]



```
cov(X.T)
```




    array([[ 0.68569351, -0.03926846,  1.27368233,  0.5169038 ],
           [-0.03926846,  0.18800403, -0.32171275, -0.11798121],
           [ 1.27368233, -0.32171275,  3.11317942,  1.29638747],
           [ 0.5169038 , -0.11798121,  1.29638747,  0.58241432]])




```
covariance_matrix = cov(standardized_data.T)
print("\n Covariance Matrix: \n", covariance_matrix)
```

    
     Covariance Matrix: 
     [[ 1.00671141 -0.11010327  0.87760486  0.82344326]
     [-0.11010327  1.00671141 -0.42333835 -0.358937  ]
     [ 0.87760486 -0.42333835  1.00671141  0.96921855]
     [ 0.82344326 -0.358937    0.96921855  1.00671141]]



```
pd.DataFrame(standardized_data, columns=['sepal_length', 'sepal_width', 'petal_length', 'petal_width']).cov()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>sepal_length</th>
      <th>sepal_width</th>
      <th>petal_length</th>
      <th>petal_width</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>sepal_length</th>
      <td>1.006711</td>
      <td>-0.110103</td>
      <td>0.877605</td>
      <td>0.823443</td>
    </tr>
    <tr>
      <th>sepal_width</th>
      <td>-0.110103</td>
      <td>1.006711</td>
      <td>-0.423338</td>
      <td>-0.358937</td>
    </tr>
    <tr>
      <th>petal_length</th>
      <td>0.877605</td>
      <td>-0.423338</td>
      <td>1.006711</td>
      <td>0.969219</td>
    </tr>
    <tr>
      <th>petal_width</th>
      <td>0.823443</td>
      <td>-0.358937</td>
      <td>0.969219</td>
      <td>1.006711</td>
    </tr>
  </tbody>
</table>
</div>




```
np.matmul(standardized_data.T, standardized_data)
```




    array([[150.        , -16.40538749, 130.7631236 , 122.69304501],
           [-16.40538749, 150.        , -63.07741446, -53.48161344],
           [130.7631236 , -63.07741446, 150.        , 144.41356456],
           [122.69304501, -53.48161344, 144.41356456, 150.        ]])




```
vals, vects = eig(covariance_matrix)
print("\n Eigenvectors: \n", vects)
print("\n Eigenvalues: \n", vals)
```

    
     Eigenvectors: 
     [[ 0.52237162 -0.37231836 -0.72101681  0.26199559]
     [-0.26335492 -0.92555649  0.24203288 -0.12413481]
     [ 0.58125401 -0.02109478  0.14089226 -0.80115427]
     [ 0.56561105 -0.06541577  0.6338014   0.52354627]]
    
     Eigenvalues: 
     [2.93035378 0.92740362 0.14834223 0.02074601]



```
P = np.dot(vects.T, standardized_data.T)
print("\n Projected Data: \n", P.T)
```

    
     Projected Data: 
     [[-2.26454173e+00 -5.05703903e-01 -1.21943348e-01  2.30733235e-02]
     [-2.08642550e+00  6.55404729e-01 -2.27250832e-01  1.03208244e-01]
     [-2.36795045e+00  3.18477311e-01  5.14796236e-02  2.78252250e-02]
     [-2.30419716e+00  5.75367713e-01  9.88604444e-02 -6.63114622e-02]
     [-2.38877749e+00 -6.74767397e-01  2.14278490e-02 -3.73972870e-02]
     [-2.07053681e+00 -1.51854856e+00  3.06842583e-02  4.39877494e-03]
     [-2.44571134e+00 -7.45626750e-02  3.42197636e-01 -3.80965668e-02]
     [-2.23384186e+00 -2.47613932e-01 -8.25744645e-02 -2.55051623e-02]
     [-2.34195768e+00  1.09514636e+00  1.53562399e-01 -2.67938291e-02]
     [-2.18867576e+00  4.48629048e-01 -2.46559522e-01 -3.99073035e-02]
     [-2.16348656e+00 -1.07059558e+00 -2.64009373e-01  1.53011377e-02]
     [-2.32737775e+00 -1.58587455e-01  1.00165616e-01 -1.34554258e-01]
     [-2.22408272e+00  7.09118158e-01 -2.23214514e-01  2.63061382e-03]
     [-2.63971626e+00  9.38281982e-01  1.89570030e-01 -1.94220183e-02]
     [-2.19229151e+00 -1.88997851e+00 -4.69480095e-01  1.92782042e-01]
     [-2.25146521e+00 -2.72237108e+00  3.26037967e-02  4.71257043e-02]
     [-2.20275048e+00 -1.51375028e+00 -1.36349158e-03  1.86631581e-01]
     [-2.19017916e+00 -5.14304308e-01 -3.86155949e-02  9.19055067e-02]
     [-1.89407429e+00 -1.43111071e+00 -3.70742834e-01  5.95280968e-02]
     [-2.33994907e+00 -1.15803343e+00  1.37417719e-01 -3.98281842e-02]
     [-1.91455639e+00 -4.30465163e-01 -4.16006875e-01  1.03602240e-02]
     [-2.20464540e+00 -9.52457317e-01  1.64738346e-01  5.77291622e-02]
     [-2.77416979e+00 -4.89517027e-01  3.38836384e-01  1.78537297e-02]
     [-1.82041156e+00 -1.06750793e-01  4.00614724e-02  1.50345595e-01]
     [-2.22821750e+00 -1.62186163e-01  1.24201428e-01 -2.71228863e-01]
     [-1.95702401e+00  6.07892567e-01 -2.98591029e-01  4.38372887e-02]
     [-2.05206331e+00 -2.66014312e-01  9.20929788e-02  6.66010028e-02]
     [-2.16819365e+00 -5.52016495e-01 -2.01295482e-01  9.26056927e-03]
     [-2.14030596e+00 -3.36640409e-01 -2.65314545e-01  8.35439339e-02]
     [-2.26879019e+00  3.14878603e-01  7.55154360e-02 -1.08849380e-01]
     [-2.14455443e+00  4.83942097e-01 -6.78557607e-02 -4.83787691e-02]
     [-1.83193810e+00 -4.45266836e-01 -2.65375244e-01  2.39140994e-01]
     [-2.60820287e+00 -1.82847519e+00  5.14195182e-02 -2.31922593e-01]
     [-2.43795086e+00 -2.18539162e+00 -7.93497549e-02 -5.10210291e-02]
     [-2.18867576e+00  4.48629048e-01 -2.46559522e-01 -3.99073035e-02]
     [-2.21111990e+00  1.84337811e-01 -2.18624528e-01  1.68619769e-01]
     [-2.04441652e+00 -6.84956426e-01 -4.79411570e-01  1.95613314e-01]
     [-2.18867576e+00  4.48629048e-01 -2.46559522e-01 -3.99073035e-02]
     [-2.43595220e+00  8.82169415e-01  2.01557587e-01 -9.96079072e-03]
     [-2.17054720e+00 -2.92726955e-01 -1.69938536e-01  6.24028506e-03]
     [-2.28652724e+00 -4.67991716e-01  4.07365390e-02  1.05718261e-01]
     [-1.87170722e+00  2.32769161e+00 -1.94528610e-01  2.91692982e-01]
     [-2.55783442e+00  4.53816380e-01  3.13571838e-01 -6.74111170e-02]
     [-1.96427929e+00 -4.97391640e-01  3.14755610e-01  1.75540206e-01]
     [-2.13337283e+00 -1.17143211e+00  2.52793222e-01 -1.53228807e-01]
     [-2.07535759e+00  6.91917347e-01 -5.65590082e-02  1.40294980e-01]
     [-2.38125822e+00 -1.15063259e+00  6.21019035e-02 -1.54218569e-01]
     [-2.39819169e+00  3.62390765e-01  1.46855632e-01 -4.94784238e-02]
     [-2.22678121e+00 -1.02548255e+00 -1.76645302e-01 -1.64443096e-02]
     [-2.20595417e+00 -3.22378453e-02 -1.46593527e-01  4.87782024e-02]
     [ 1.10399365e+00 -8.63112446e-01 -6.85555108e-01  3.49778613e-02]
     [ 7.32481440e-01 -5.98635573e-01 -9.40668020e-02  4.45376367e-03]
     [ 1.24210951e+00 -6.14822450e-01 -5.54846534e-01  9.67335738e-03]
     [ 3.97307283e-01  1.75816895e+00 -1.85694824e-02  6.73978468e-02]
     [ 1.07259395e+00  2.11757903e-01 -3.97447438e-01  1.05541662e-01]
     [ 3.84458146e-01  5.91062469e-01  1.26797690e-01 -2.40528082e-01]
     [ 7.48715076e-01 -7.78698611e-01  1.48656023e-01 -7.83010665e-02]
     [-4.97863388e-01  1.84886877e+00  2.55555250e-01 -3.93891395e-02]
     [ 9.26222368e-01 -3.03308268e-02 -5.95459889e-01 -2.91024204e-02]
     [ 4.96802558e-03  1.02940111e+00  5.42867049e-01 -2.83487629e-02]
     [-1.24697461e-01  2.65806268e+00 -3.98134482e-02  1.61405573e-02]
     [ 4.38730118e-01  5.88812850e-02  2.06703491e-01  3.98514578e-02]
     [ 5.51633981e-01  1.77258156e+00 -7.61380223e-01  4.83536968e-02]
     [ 7.17165066e-01  1.85434315e-01 -6.72998424e-02 -1.64555675e-01]
     [-3.72583830e-02  4.32795099e-01  1.98061449e-01  1.09025121e-01]
     [ 8.75890536e-01 -5.09998151e-01 -5.03505832e-01  1.05141287e-01]
     [ 3.48006402e-01  1.90621647e-01  4.92831518e-01 -1.92059489e-01]
     [ 1.53392545e-01  7.90725456e-01 -2.98604516e-01 -2.04321215e-01]
     [ 1.21530321e+00  1.63335564e+00 -4.79409914e-01  2.28214500e-01]
     [ 1.56941176e-01  1.30310327e+00 -1.68586746e-01 -5.04131971e-02]
     [ 7.38256104e-01 -4.02470382e-01  6.16772626e-01 -8.44515277e-02]
     [ 4.72369682e-01  4.16608222e-01 -2.62718283e-01  1.14244715e-01]
     [ 1.22798821e+00  9.40914793e-01 -3.66704859e-01 -8.44834785e-03]
     [ 6.29381045e-01  4.16811643e-01 -2.89962474e-01 -2.73494879e-01]
     [ 7.00472799e-01  6.34939277e-02 -4.44767559e-01  4.40812895e-02]
     [ 8.73536987e-01 -2.50708611e-01 -4.72148886e-01  1.02121003e-01]
     [ 1.25422219e+00  8.26200998e-02 -7.26843529e-01  4.08294177e-02]
     [ 1.35823985e+00 -3.28820266e-01 -2.61458074e-01  6.70137909e-02]
     [ 6.62126138e-01  2.24346071e-01  8.73681069e-02 -3.63525363e-02]
     [-4.72815133e-02  1.05721241e+00 -3.15319195e-01  6.60077099e-02]
     [ 1.21534209e-01  1.56359238e+00 -1.45241738e-01 -7.87527979e-03]
     [ 1.41182261e-02  1.57339235e+00 -2.36581428e-01 -3.11492615e-02]
     [ 2.36010837e-01  7.75923784e-01 -1.47972885e-01  2.44595546e-02]
     [ 1.05669143e+00  6.36901284e-01  1.06753234e-01 -1.83419236e-01]
     [ 2.21417088e-01  2.80847693e-01  6.67559660e-01 -2.55550383e-01]
     [ 4.31783161e-01 -8.55136920e-01  4.50731487e-01 -1.11146169e-01]
     [ 1.04941336e+00 -5.22197265e-01 -3.96142266e-01  3.72988658e-02]
     [ 1.03587821e+00  1.39246648e+00 -6.85434303e-01  1.39128619e-01]
     [ 6.70675999e-02  2.12620735e-01  2.94128262e-01 -1.47491049e-01]
     [ 2.75425066e-01  1.32981591e+00  9.34447685e-02  9.94752060e-03]
     [ 2.72335066e-01  1.11944152e+00  9.81718909e-02 -2.69842632e-01]
     [ 6.23170540e-01 -2.75426333e-02 -1.93046544e-02 -1.47722637e-01]
     [ 3.30005364e-01  9.88900732e-01 -1.95968073e-01  7.62651620e-03]
     [-3.73627623e-01  2.01793227e+00  1.12184053e-01  2.10814710e-02]
     [ 2.82944343e-01  8.53950717e-01  1.34118823e-01 -1.06873761e-01]
     [ 8.90531103e-02  1.74908548e-01  1.31448375e-01 -2.30135987e-01]
     [ 2.24356783e-01  3.80484659e-01  1.58769003e-01 -1.32578640e-01]
     [ 5.73883486e-01  1.53719974e-01 -2.70039416e-01 -1.94096051e-02]
     [-4.57012873e-01  1.53946451e+00  1.96126173e-01  2.00883380e-01]
     [ 2.52244473e-01  5.95860746e-01  9.47499397e-02 -5.82952756e-02]
     [ 1.84767259e+00 -8.71696662e-01  1.00276099e+00 -5.10680368e-02]
     [ 1.15318981e+00  7.01326114e-01  5.31464635e-01 -4.04135807e-02]
     [ 2.20634950e+00 -5.54470105e-01 -2.05495910e-01  5.93004996e-02]
     [ 1.43868540e+00  5.00105223e-02  1.63390464e-01 -2.35759861e-01]
     [ 1.86789070e+00 -2.91192802e-01  3.94004333e-01 -1.67817996e-02]
     [ 2.75419671e+00 -7.88432206e-01 -5.86232704e-01 -1.00879674e-01]
     [ 3.58374475e-01  1.56009458e+00  9.90999895e-01 -1.32987438e-01]
     [ 2.30300590e+00 -4.09516695e-01 -6.54166687e-01 -2.37212798e-01]
     [ 2.00173530e+00  7.23865359e-01 -3.94070448e-01 -8.49938224e-02]
     [ 2.26755460e+00 -1.92144299e+00  3.92517658e-01  1.02907298e-01]
     [ 1.36590943e+00 -6.93948040e-01  2.83279516e-01  1.07010918e-01]
     [ 1.59906459e+00  4.28248836e-01  2.33040821e-02  5.89427002e-02]
     [ 1.88425185e+00 -4.14332758e-01  2.45485540e-02  1.46296964e-01]
     [ 1.25308651e+00  1.16739134e+00  5.82130271e-01  9.96816830e-02]
     [ 1.46406152e+00  4.44147569e-01  1.00411052e+00  2.75022173e-01]
     [ 1.59180930e+00 -6.77035372e-01  6.36650721e-01  1.90645618e-01]
     [ 1.47128019e+00 -2.53192472e-01  3.66575092e-02 -1.55435928e-01]
     [ 2.43737848e+00 -2.55675734e+00 -1.34200082e-01 -2.75661550e-01]
     [ 3.30914118e+00  2.36132010e-03 -7.06933959e-01  4.67561875e-02]
     [ 1.25398099e+00  1.71758384e+00 -2.64622084e-01 -6.30674020e-02]
     [ 2.04049626e+00 -9.07398765e-01  2.31878114e-01  1.67140048e-01]
     [ 9.73915114e-01  5.71174376e-01  8.29503781e-01  2.73189478e-02]
     [ 2.89806444e+00 -3.97791359e-01 -8.60926842e-01 -1.26074286e-01]
     [ 1.32919369e+00  4.86760542e-01 -4.70734933e-03  1.40597876e-01]
     [ 1.70424071e+00 -1.01414842e+00  2.95957877e-01 -6.27403760e-02]
     [ 1.95772766e+00 -1.00333452e+00 -4.22817052e-01 -2.18459131e-01]
     [ 1.17190451e+00  3.18896617e-01  1.30651910e-01  1.25685467e-01]
     [ 1.01978105e+00 -6.55429631e-02  3.38042170e-01 -9.06850833e-03]
     [ 1.78600886e+00  1.93272800e-01  2.70002526e-01  3.12072991e-02]
     [ 1.86477791e+00 -5.55381532e-01 -7.17510683e-01 -2.07556768e-01]
     [ 2.43549739e+00 -2.46654468e-01 -7.30234006e-01 -1.67936017e-02]
     [ 2.31608241e+00 -2.62618387e+00 -4.99619543e-01 -2.13160418e-01]
     [ 1.86037143e+00  1.84672394e-01  3.53330279e-01  1.00039482e-01]
     [ 1.11127173e+00  2.95986102e-01 -1.82659608e-01 -1.85740240e-01]
     [ 1.19746916e+00  8.17167742e-01 -1.63213782e-01 -4.88404000e-01]
     [ 2.80094940e+00 -8.44748194e-01 -5.47000957e-01  2.96321147e-01]
     [ 1.58015525e+00 -1.07247450e+00  9.43392608e-01  3.36074229e-02]
     [ 1.34704442e+00 -4.22255966e-01  1.80028706e-01 -2.15906539e-01]
     [ 9.23432978e-01 -1.92303705e-02  4.17394303e-01  4.74424586e-03]
     [ 1.85355198e+00 -6.72422729e-01 -1.48203294e-02  1.94875449e-01]
     [ 2.01615720e+00 -6.10397038e-01  4.25914947e-01  2.46764702e-01]
     [ 1.90311686e+00 -6.86024832e-01  1.27799364e-01  4.69214421e-01]
     [ 1.15318981e+00  7.01326114e-01  5.31464635e-01 -4.04135807e-02]
     [ 2.04330844e+00 -8.64684880e-01  3.35266061e-01  4.42781979e-02]
     [ 2.00169097e+00 -1.04855005e+00  6.29268888e-01  2.12588357e-01]
     [ 1.87052207e+00 -3.82821838e-01  2.54532319e-01  3.88890487e-01]
     [ 1.55849189e+00  9.05313601e-01 -2.53819099e-02  2.21322184e-01]
     [ 1.52084506e+00 -2.66794575e-01  1.79277203e-01  1.18903043e-01]
     [ 1.37639119e+00 -1.01636193e+00  9.31405052e-01  2.41461953e-02]
     [ 9.59298576e-01  2.22839447e-02  5.28794187e-01 -1.63675806e-01]]



```
data = {"x": P[0], "y": P[1]}

df = pd.DataFrame(data)

plt.scatter(df['x'], df['y'])
plt.title("Iris Data After PCA")
plt.show()
```


```
from numpy import array
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
```


```
Z = StandardScaler().fit_transform(X)
print("\n Standardized Data: \n", Z)
```

    
     Standardized Data: 
     [[-9.00681170e-01  1.03205722e+00 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00 -1.24957601e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.38535265e+00  3.37848329e-01 -1.39813811e+00 -1.31297673e+00]
     [-1.50652052e+00  1.06445364e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  1.26346019e+00 -1.34127240e+00 -1.31297673e+00]
     [-5.37177559e-01  1.95766909e+00 -1.17067529e+00 -1.05003079e+00]
     [-1.50652052e+00  8.00654259e-01 -1.34127240e+00 -1.18150376e+00]
     [-1.02184904e+00  8.00654259e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.74885626e+00 -3.56360566e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-5.37177559e-01  1.49486315e+00 -1.28440670e+00 -1.31297673e+00]
     [-1.26418478e+00  8.00654259e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.26418478e+00 -1.24957601e-01 -1.34127240e+00 -1.44444970e+00]
     [-1.87002413e+00 -1.24957601e-01 -1.51186952e+00 -1.44444970e+00]
     [-5.25060772e-02  2.18907205e+00 -1.45500381e+00 -1.31297673e+00]
     [-1.73673948e-01  3.11468391e+00 -1.28440670e+00 -1.05003079e+00]
     [-5.37177559e-01  1.95766909e+00 -1.39813811e+00 -1.05003079e+00]
     [-9.00681170e-01  1.03205722e+00 -1.34127240e+00 -1.18150376e+00]
     [-1.73673948e-01  1.72626612e+00 -1.17067529e+00 -1.18150376e+00]
     [-9.00681170e-01  1.72626612e+00 -1.28440670e+00 -1.18150376e+00]
     [-5.37177559e-01  8.00654259e-01 -1.17067529e+00 -1.31297673e+00]
     [-9.00681170e-01  1.49486315e+00 -1.28440670e+00 -1.05003079e+00]
     [-1.50652052e+00  1.26346019e+00 -1.56873522e+00 -1.31297673e+00]
     [-9.00681170e-01  5.69251294e-01 -1.17067529e+00 -9.18557817e-01]
     [-1.26418478e+00  8.00654259e-01 -1.05694388e+00 -1.31297673e+00]
     [-1.02184904e+00 -1.24957601e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.02184904e+00  8.00654259e-01 -1.22754100e+00 -1.05003079e+00]
     [-7.79513300e-01  1.03205722e+00 -1.28440670e+00 -1.31297673e+00]
     [-7.79513300e-01  8.00654259e-01 -1.34127240e+00 -1.31297673e+00]
     [-1.38535265e+00  3.37848329e-01 -1.22754100e+00 -1.31297673e+00]
     [-1.26418478e+00  1.06445364e-01 -1.22754100e+00 -1.31297673e+00]
     [-5.37177559e-01  8.00654259e-01 -1.28440670e+00 -1.05003079e+00]
     [-7.79513300e-01  2.42047502e+00 -1.28440670e+00 -1.44444970e+00]
     [-4.16009689e-01  2.65187798e+00 -1.34127240e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-1.02184904e+00  3.37848329e-01 -1.45500381e+00 -1.31297673e+00]
     [-4.16009689e-01  1.03205722e+00 -1.39813811e+00 -1.31297673e+00]
     [-1.14301691e+00  1.06445364e-01 -1.28440670e+00 -1.44444970e+00]
     [-1.74885626e+00 -1.24957601e-01 -1.39813811e+00 -1.31297673e+00]
     [-9.00681170e-01  8.00654259e-01 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  1.03205722e+00 -1.39813811e+00 -1.18150376e+00]
     [-1.62768839e+00 -1.74477836e+00 -1.39813811e+00 -1.18150376e+00]
     [-1.74885626e+00  3.37848329e-01 -1.39813811e+00 -1.31297673e+00]
     [-1.02184904e+00  1.03205722e+00 -1.22754100e+00 -7.87084847e-01]
     [-9.00681170e-01  1.72626612e+00 -1.05694388e+00 -1.05003079e+00]
     [-1.26418478e+00 -1.24957601e-01 -1.34127240e+00 -1.18150376e+00]
     [-9.00681170e-01  1.72626612e+00 -1.22754100e+00 -1.31297673e+00]
     [-1.50652052e+00  3.37848329e-01 -1.34127240e+00 -1.31297673e+00]
     [-6.58345429e-01  1.49486315e+00 -1.28440670e+00 -1.31297673e+00]
     [-1.02184904e+00  5.69251294e-01 -1.34127240e+00 -1.31297673e+00]
     [ 1.40150837e+00  3.37848329e-01  5.35295827e-01  2.64698913e-01]
     [ 6.74501145e-01  3.37848329e-01  4.21564419e-01  3.96171883e-01]
     [ 1.28034050e+00  1.06445364e-01  6.49027235e-01  3.96171883e-01]
     [-4.16009689e-01 -1.74477836e+00  1.37235899e-01  1.33225943e-01]
     [ 7.95669016e-01 -5.87763531e-01  4.78430123e-01  3.96171883e-01]
     [-1.73673948e-01 -5.87763531e-01  4.21564419e-01  1.33225943e-01]
     [ 5.53333275e-01  5.69251294e-01  5.35295827e-01  5.27644853e-01]
     [-1.14301691e+00 -1.51337539e+00 -2.60824029e-01 -2.61192967e-01]
     [ 9.16836886e-01 -3.56360566e-01  4.78430123e-01  1.33225943e-01]
     [-7.79513300e-01 -8.19166497e-01  8.03701950e-02  2.64698913e-01]
     [-1.02184904e+00 -2.43898725e+00 -1.47092621e-01 -2.61192967e-01]
     [ 6.86617933e-02 -1.24957601e-01  2.50967307e-01  3.96171883e-01]
     [ 1.89829664e-01 -1.97618132e+00  1.37235899e-01 -2.61192967e-01]
     [ 3.10997534e-01 -3.56360566e-01  5.35295827e-01  2.64698913e-01]
     [-2.94841818e-01 -3.56360566e-01 -9.02269170e-02  1.33225943e-01]
     [ 1.03800476e+00  1.06445364e-01  3.64698715e-01  2.64698913e-01]
     [-2.94841818e-01 -1.24957601e-01  4.21564419e-01  3.96171883e-01]
     [-5.25060772e-02 -8.19166497e-01  1.94101603e-01 -2.61192967e-01]
     [ 4.32165405e-01 -1.97618132e+00  4.21564419e-01  3.96171883e-01]
     [-2.94841818e-01 -1.28197243e+00  8.03701950e-02 -1.29719997e-01]
     [ 6.86617933e-02  3.37848329e-01  5.92161531e-01  7.90590793e-01]
     [ 3.10997534e-01 -5.87763531e-01  1.37235899e-01  1.33225943e-01]
     [ 5.53333275e-01 -1.28197243e+00  6.49027235e-01  3.96171883e-01]
     [ 3.10997534e-01 -5.87763531e-01  5.35295827e-01  1.75297293e-03]
     [ 6.74501145e-01 -3.56360566e-01  3.07833011e-01  1.33225943e-01]
     [ 9.16836886e-01 -1.24957601e-01  3.64698715e-01  2.64698913e-01]
     [ 1.15917263e+00 -5.87763531e-01  5.92161531e-01  2.64698913e-01]
     [ 1.03800476e+00 -1.24957601e-01  7.05892939e-01  6.59117823e-01]
     [ 1.89829664e-01 -3.56360566e-01  4.21564419e-01  3.96171883e-01]
     [-1.73673948e-01 -1.05056946e+00 -1.47092621e-01 -2.61192967e-01]
     [-4.16009689e-01 -1.51337539e+00  2.35044910e-02 -1.29719997e-01]
     [-4.16009689e-01 -1.51337539e+00 -3.33612130e-02 -2.61192967e-01]
     [-5.25060772e-02 -8.19166497e-01  8.03701950e-02  1.75297293e-03]
     [ 1.89829664e-01 -8.19166497e-01  7.62758643e-01  5.27644853e-01]
     [-5.37177559e-01 -1.24957601e-01  4.21564419e-01  3.96171883e-01]
     [ 1.89829664e-01  8.00654259e-01  4.21564419e-01  5.27644853e-01]
     [ 1.03800476e+00  1.06445364e-01  5.35295827e-01  3.96171883e-01]
     [ 5.53333275e-01 -1.74477836e+00  3.64698715e-01  1.33225943e-01]
     [-2.94841818e-01 -1.24957601e-01  1.94101603e-01  1.33225943e-01]
     [-4.16009689e-01 -1.28197243e+00  1.37235899e-01  1.33225943e-01]
     [-4.16009689e-01 -1.05056946e+00  3.64698715e-01  1.75297293e-03]
     [ 3.10997534e-01 -1.24957601e-01  4.78430123e-01  2.64698913e-01]
     [-5.25060772e-02 -1.05056946e+00  1.37235899e-01  1.75297293e-03]
     [-1.02184904e+00 -1.74477836e+00 -2.60824029e-01 -2.61192967e-01]
     [-2.94841818e-01 -8.19166497e-01  2.50967307e-01  1.33225943e-01]
     [-1.73673948e-01 -1.24957601e-01  2.50967307e-01  1.75297293e-03]
     [-1.73673948e-01 -3.56360566e-01  2.50967307e-01  1.33225943e-01]
     [ 4.32165405e-01 -3.56360566e-01  3.07833011e-01  1.33225943e-01]
     [-9.00681170e-01 -1.28197243e+00 -4.31421141e-01 -1.29719997e-01]
     [-1.73673948e-01 -5.87763531e-01  1.94101603e-01  1.33225943e-01]
     [ 5.53333275e-01  5.69251294e-01  1.27454998e+00  1.71090158e+00]
     [-5.25060772e-02 -8.19166497e-01  7.62758643e-01  9.22063763e-01]
     [ 1.52267624e+00 -1.24957601e-01  1.21768427e+00  1.18500970e+00]
     [ 5.53333275e-01 -3.56360566e-01  1.04708716e+00  7.90590793e-01]
     [ 7.95669016e-01 -1.24957601e-01  1.16081857e+00  1.31648267e+00]
     [ 2.12851559e+00 -1.24957601e-01  1.61574420e+00  1.18500970e+00]
     [-1.14301691e+00 -1.28197243e+00  4.21564419e-01  6.59117823e-01]
     [ 1.76501198e+00 -3.56360566e-01  1.44514709e+00  7.90590793e-01]
     [ 1.03800476e+00 -1.28197243e+00  1.16081857e+00  7.90590793e-01]
     [ 1.64384411e+00  1.26346019e+00  1.33141568e+00  1.71090158e+00]
     [ 7.95669016e-01  3.37848329e-01  7.62758643e-01  1.05353673e+00]
     [ 6.74501145e-01 -8.19166497e-01  8.76490051e-01  9.22063763e-01]
     [ 1.15917263e+00 -1.24957601e-01  9.90221459e-01  1.18500970e+00]
     [-1.73673948e-01 -1.28197243e+00  7.05892939e-01  1.05353673e+00]
     [-5.25060772e-02 -5.87763531e-01  7.62758643e-01  1.57942861e+00]
     [ 6.74501145e-01  3.37848329e-01  8.76490051e-01  1.44795564e+00]
     [ 7.95669016e-01 -1.24957601e-01  9.90221459e-01  7.90590793e-01]
     [ 2.24968346e+00  1.72626612e+00  1.67260991e+00  1.31648267e+00]
     [ 2.24968346e+00 -1.05056946e+00  1.78634131e+00  1.44795564e+00]
     [ 1.89829664e-01 -1.97618132e+00  7.05892939e-01  3.96171883e-01]
     [ 1.28034050e+00  3.37848329e-01  1.10395287e+00  1.44795564e+00]
     [-2.94841818e-01 -5.87763531e-01  6.49027235e-01  1.05353673e+00]
     [ 2.24968346e+00 -5.87763531e-01  1.67260991e+00  1.05353673e+00]
     [ 5.53333275e-01 -8.19166497e-01  6.49027235e-01  7.90590793e-01]
     [ 1.03800476e+00  5.69251294e-01  1.10395287e+00  1.18500970e+00]
     [ 1.64384411e+00  3.37848329e-01  1.27454998e+00  7.90590793e-01]
     [ 4.32165405e-01 -5.87763531e-01  5.92161531e-01  7.90590793e-01]
     [ 3.10997534e-01 -1.24957601e-01  6.49027235e-01  7.90590793e-01]
     [ 6.74501145e-01 -5.87763531e-01  1.04708716e+00  1.18500970e+00]
     [ 1.64384411e+00 -1.24957601e-01  1.16081857e+00  5.27644853e-01]
     [ 1.88617985e+00 -5.87763531e-01  1.33141568e+00  9.22063763e-01]
     [ 2.49201920e+00  1.72626612e+00  1.50201279e+00  1.05353673e+00]
     [ 6.74501145e-01 -5.87763531e-01  1.04708716e+00  1.31648267e+00]
     [ 5.53333275e-01 -5.87763531e-01  7.62758643e-01  3.96171883e-01]
     [ 3.10997534e-01 -1.05056946e+00  1.04708716e+00  2.64698913e-01]
     [ 2.24968346e+00 -1.24957601e-01  1.33141568e+00  1.44795564e+00]
     [ 5.53333275e-01  8.00654259e-01  1.04708716e+00  1.57942861e+00]
     [ 6.74501145e-01  1.06445364e-01  9.90221459e-01  7.90590793e-01]
     [ 1.89829664e-01 -1.24957601e-01  5.92161531e-01  7.90590793e-01]
     [ 1.28034050e+00  1.06445364e-01  9.33355755e-01  1.18500970e+00]
     [ 1.03800476e+00  1.06445364e-01  1.04708716e+00  1.57942861e+00]
     [ 1.28034050e+00  1.06445364e-01  7.62758643e-01  1.44795564e+00]
     [-5.25060772e-02 -8.19166497e-01  7.62758643e-01  9.22063763e-01]
     [ 1.15917263e+00  3.37848329e-01  1.21768427e+00  1.44795564e+00]
     [ 1.03800476e+00  5.69251294e-01  1.10395287e+00  1.71090158e+00]
     [ 1.03800476e+00 -1.24957601e-01  8.19624347e-01  1.44795564e+00]
     [ 5.53333275e-01 -1.28197243e+00  7.05892939e-01  9.22063763e-01]
     [ 7.95669016e-01 -1.24957601e-01  8.19624347e-01  1.05353673e+00]
     [ 4.32165405e-01  8.00654259e-01  9.33355755e-01  1.44795564e+00]
     [ 6.86617933e-02 -1.24957601e-01  7.62758643e-01  7.90590793e-01]]



```
pca = PCA(2)
pca.fit(Z)

print("\n Eigenvectors: \n", pca.components_)
print("\n Eigenvalues: \n", pca.explained_variance_)
```

    
     Eigenvectors: 
     [[ 0.52237162 -0.26335492  0.58125401  0.56561105]
     [ 0.37231836  0.92555649  0.02109478  0.06541577]]
    
     Eigenvalues: 
     [2.93035378 0.92740362]


That second vector was negative in the previous analysis.


```
B = pca.transform(Z)

print("\n Projected Data: \n", B)
```

    
     Projected Data: 
     [[-2.26454173e+00  5.05703903e-01]
     [-2.08642550e+00 -6.55404729e-01]
     [-2.36795045e+00 -3.18477311e-01]
     [-2.30419716e+00 -5.75367713e-01]
     [-2.38877749e+00  6.74767397e-01]
     [-2.07053681e+00  1.51854856e+00]
     [-2.44571134e+00  7.45626750e-02]
     [-2.23384186e+00  2.47613932e-01]
     [-2.34195768e+00 -1.09514636e+00]
     [-2.18867576e+00 -4.48629048e-01]
     [-2.16348656e+00  1.07059558e+00]
     [-2.32737775e+00  1.58587455e-01]
     [-2.22408272e+00 -7.09118158e-01]
     [-2.63971626e+00 -9.38281982e-01]
     [-2.19229151e+00  1.88997851e+00]
     [-2.25146521e+00  2.72237108e+00]
     [-2.20275048e+00  1.51375028e+00]
     [-2.19017916e+00  5.14304308e-01]
     [-1.89407429e+00  1.43111071e+00]
     [-2.33994907e+00  1.15803343e+00]
     [-1.91455639e+00  4.30465163e-01]
     [-2.20464540e+00  9.52457317e-01]
     [-2.77416979e+00  4.89517027e-01]
     [-1.82041156e+00  1.06750793e-01]
     [-2.22821750e+00  1.62186163e-01]
     [-1.95702401e+00 -6.07892567e-01]
     [-2.05206331e+00  2.66014312e-01]
     [-2.16819365e+00  5.52016495e-01]
     [-2.14030596e+00  3.36640409e-01]
     [-2.26879019e+00 -3.14878603e-01]
     [-2.14455443e+00 -4.83942097e-01]
     [-1.83193810e+00  4.45266836e-01]
     [-2.60820287e+00  1.82847519e+00]
     [-2.43795086e+00  2.18539162e+00]
     [-2.18867576e+00 -4.48629048e-01]
     [-2.21111990e+00 -1.84337811e-01]
     [-2.04441652e+00  6.84956426e-01]
     [-2.18867576e+00 -4.48629048e-01]
     [-2.43595220e+00 -8.82169415e-01]
     [-2.17054720e+00  2.92726955e-01]
     [-2.28652724e+00  4.67991716e-01]
     [-1.87170722e+00 -2.32769161e+00]
     [-2.55783442e+00 -4.53816380e-01]
     [-1.96427929e+00  4.97391640e-01]
     [-2.13337283e+00  1.17143211e+00]
     [-2.07535759e+00 -6.91917347e-01]
     [-2.38125822e+00  1.15063259e+00]
     [-2.39819169e+00 -3.62390765e-01]
     [-2.22678121e+00  1.02548255e+00]
     [-2.20595417e+00  3.22378453e-02]
     [ 1.10399365e+00  8.63112446e-01]
     [ 7.32481440e-01  5.98635573e-01]
     [ 1.24210951e+00  6.14822450e-01]
     [ 3.97307283e-01 -1.75816895e+00]
     [ 1.07259395e+00 -2.11757903e-01]
     [ 3.84458146e-01 -5.91062469e-01]
     [ 7.48715076e-01  7.78698611e-01]
     [-4.97863388e-01 -1.84886877e+00]
     [ 9.26222368e-01  3.03308268e-02]
     [ 4.96802558e-03 -1.02940111e+00]
     [-1.24697461e-01 -2.65806268e+00]
     [ 4.38730118e-01 -5.88812850e-02]
     [ 5.51633981e-01 -1.77258156e+00]
     [ 7.17165066e-01 -1.85434315e-01]
     [-3.72583830e-02 -4.32795099e-01]
     [ 8.75890536e-01  5.09998151e-01]
     [ 3.48006402e-01 -1.90621647e-01]
     [ 1.53392545e-01 -7.90725456e-01]
     [ 1.21530321e+00 -1.63335564e+00]
     [ 1.56941176e-01 -1.30310327e+00]
     [ 7.38256104e-01  4.02470382e-01]
     [ 4.72369682e-01 -4.16608222e-01]
     [ 1.22798821e+00 -9.40914793e-01]
     [ 6.29381045e-01 -4.16811643e-01]
     [ 7.00472799e-01 -6.34939277e-02]
     [ 8.73536987e-01  2.50708611e-01]
     [ 1.25422219e+00 -8.26200998e-02]
     [ 1.35823985e+00  3.28820266e-01]
     [ 6.62126138e-01 -2.24346071e-01]
     [-4.72815133e-02 -1.05721241e+00]
     [ 1.21534209e-01 -1.56359238e+00]
     [ 1.41182261e-02 -1.57339235e+00]
     [ 2.36010837e-01 -7.75923784e-01]
     [ 1.05669143e+00 -6.36901284e-01]
     [ 2.21417088e-01 -2.80847693e-01]
     [ 4.31783161e-01  8.55136920e-01]
     [ 1.04941336e+00  5.22197265e-01]
     [ 1.03587821e+00 -1.39246648e+00]
     [ 6.70675999e-02 -2.12620735e-01]
     [ 2.75425066e-01 -1.32981591e+00]
     [ 2.72335066e-01 -1.11944152e+00]
     [ 6.23170540e-01  2.75426333e-02]
     [ 3.30005364e-01 -9.88900732e-01]
     [-3.73627623e-01 -2.01793227e+00]
     [ 2.82944343e-01 -8.53950717e-01]
     [ 8.90531103e-02 -1.74908548e-01]
     [ 2.24356783e-01 -3.80484659e-01]
     [ 5.73883486e-01 -1.53719974e-01]
     [-4.57012873e-01 -1.53946451e+00]
     [ 2.52244473e-01 -5.95860746e-01]
     [ 1.84767259e+00  8.71696662e-01]
     [ 1.15318981e+00 -7.01326114e-01]
     [ 2.20634950e+00  5.54470105e-01]
     [ 1.43868540e+00 -5.00105223e-02]
     [ 1.86789070e+00  2.91192802e-01]
     [ 2.75419671e+00  7.88432206e-01]
     [ 3.58374475e-01 -1.56009458e+00]
     [ 2.30300590e+00  4.09516695e-01]
     [ 2.00173530e+00 -7.23865359e-01]
     [ 2.26755460e+00  1.92144299e+00]
     [ 1.36590943e+00  6.93948040e-01]
     [ 1.59906459e+00 -4.28248836e-01]
     [ 1.88425185e+00  4.14332758e-01]
     [ 1.25308651e+00 -1.16739134e+00]
     [ 1.46406152e+00 -4.44147569e-01]
     [ 1.59180930e+00  6.77035372e-01]
     [ 1.47128019e+00  2.53192472e-01]
     [ 2.43737848e+00  2.55675734e+00]
     [ 3.30914118e+00 -2.36132010e-03]
     [ 1.25398099e+00 -1.71758384e+00]
     [ 2.04049626e+00  9.07398765e-01]
     [ 9.73915114e-01 -5.71174376e-01]
     [ 2.89806444e+00  3.97791359e-01]
     [ 1.32919369e+00 -4.86760542e-01]
     [ 1.70424071e+00  1.01414842e+00]
     [ 1.95772766e+00  1.00333452e+00]
     [ 1.17190451e+00 -3.18896617e-01]
     [ 1.01978105e+00  6.55429631e-02]
     [ 1.78600886e+00 -1.93272800e-01]
     [ 1.86477791e+00  5.55381532e-01]
     [ 2.43549739e+00  2.46654468e-01]
     [ 2.31608241e+00  2.62618387e+00]
     [ 1.86037143e+00 -1.84672394e-01]
     [ 1.11127173e+00 -2.95986102e-01]
     [ 1.19746916e+00 -8.17167742e-01]
     [ 2.80094940e+00  8.44748194e-01]
     [ 1.58015525e+00  1.07247450e+00]
     [ 1.34704442e+00  4.22255966e-01]
     [ 9.23432978e-01  1.92303705e-02]
     [ 1.85355198e+00  6.72422729e-01]
     [ 2.01615720e+00  6.10397038e-01]
     [ 1.90311686e+00  6.86024832e-01]
     [ 1.15318981e+00 -7.01326114e-01]
     [ 2.04330844e+00  8.64684880e-01]
     [ 2.00169097e+00  1.04855005e+00]
     [ 1.87052207e+00  3.82821838e-01]
     [ 1.55849189e+00 -9.05313601e-01]
     [ 1.52084506e+00  2.66794575e-01]
     [ 1.37639119e+00  1.01636193e+00]
     [ 9.59298576e-01 -2.22839447e-02]]



```
# It's upside-down, for some reason.
data = {"x": B.T[0], "y": B.T[1]}

df = pd.DataFrame(data)

plt.scatter(df['x'], df['y'])
plt.title("Iris Data After PCA")
plt.show()
```

# Stretch Goal

## 1) Do NOT work on the stretch goal until you feel like you have a firm grasp of eigenvectors, eigenvalues, and PCA. Prioritize self-study over the stretch goal if you are not comfortable with those topics yet.

## 2) Explore further the intuition behind eigenvalues and eigenvectors by creating your very own eigenfaces:

<center></center>

You don't necessarily have to use this resource, but this will get you started: 
[Eigenface Tutorial](https://sandipanweb.wordpress.com/2018/01/06/eigenfaces-and-a-simple-face-detector-with-pca-svd-in-python/)

85c6e598f770ba6f0ac4369e169a21f8f4709abf
ipynb
Jupyter Notebook
module3-dimensionality-reduction/DS7_High_Dimensional_Data_Assignment.ipynb
AHartNtkn/AB-Demo
da2f76a02b9849b4c638b816ad039890143ea27e
MIT
module3-dimensionality-reduction/DS7_High_Dimensional_Data_Assignment.ipynb
AHartNtkn/AB-Demo
da2f76a02b9849b4c638b816ad039890143ea27e
MIT
module3-dimensionality-reduction/DS7_High_Dimensional_Data_Assignment.ipynb
AHartNtkn/AB-Demo
da2f76a02b9849b4c638b816ad039890143ea27e
MIT
Qwen/Qwen-72B
1. YES
2. YES