# Statistics

## 1.1 Sales for the past week was the following amounts: [3505, 2400, 3027, 2798, 3700, 3250, 2689]. Without using library functions, what is the mean, variance, and standard deviation of of sales from last week? (for extra bonus points, write your own function that can calculate these two values for any sized list)


```
# mean
amounts = [3505, 2400, 3027, 2798, 3700, 3520, 2689]
mean_value = sum(amounts)/len(amounts)
print("mean is: " + str(mean_value))

```

    mean is: 3091.285714285714



```
# standard deviation
def stdev(List):
  avg=sum(List)*1.0/len(List)
  var=list(map(lambda x: (x - avg)**2, List))
  return(sum(var)*1.0/len(var))**0.5
print(stdev(amounts))
```

    455.9679544772901



```
def var(values):
  return mean([(i-mean_value) ** 2 for i in values])
print(var(amounts))
```

    207906.7755102041



```
import numpy as np
import math
import pandas as pd
```


```
# checking from lecture
def subtract_mean(number):
  return number-mean_value

lambda x:x-mean_value
```




    <function __main__.<lambda>>




```
distances = list(map(subtract_mean, amounts))
distances
```




    [413.7142857142858,
     -691.2857142857142,
     -64.28571428571422,
     -293.2857142857142,
     608.7142857142858,
     428.7142857142858,
     -402.2857142857142]




```
squared_distances = list(map(lambda x:x**2, distances))
```


```
list_length = len(squared_distances)-1
list_length
```




    6




```
# variance
variance_amounts = sum(squared_distances)/list_length
variance_amounts
```




    242557.90476190482




```
df['amounts'].mean()
```




    3091.285714285714




```
print(df['amounts'].var(ddof=0))
print(df['amounts'].std(ddof=1))

# used 0 for ddof in var to check on the value i got for the function created above
```

    207906.7755102041
    492.5016799584595


## 1.2 Find the covariance between last week's sales numbers and the number of customers that entered the store last week: [127, 80, 105, 92, 120, 115, 93] (you may use librray functions for calculating the covariance since we didn't specifically talk about its formula)


```
# new list
customers = [127, 80, 105, 92, 120, 115, 93]
```


```
# cov from numpy
np.cov(amounts, customers)
```




    array([[242557.9047619 ,   8073.64285714],
           [  8073.64285714,    290.95238095]])




```
pd.DataFrame(np.cov(amounts, customers))
```




<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>0</th>
      <th>1</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>242557.904762</td>
      <td>8073.642857</td>
    </tr>
    <tr>
      <th>1</th>
      <td>8073.642857</td>
      <td>290.952381</td>
    </tr>
  </tbody>
</table>
</div>




```
df = pd.DataFrame({'amounts': amounts})
df['customers'] = pd.Series(customers)
df
```




<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>amounts</th>
      <th>customers</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>3505</td>
      <td>127</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2400</td>
      <td>80</td>
    </tr>
    <tr>
      <th>2</th>
      <td>3027</td>
      <td>105</td>
    </tr>
    <tr>
      <th>3</th>
      <td>2798</td>
      <td>92</td>
    </tr>
    <tr>
      <th>4</th>
      <td>3700</td>
      <td>120</td>
    </tr>
    <tr>
      <th>5</th>
      <td>3520</td>
      <td>115</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2689</td>
      <td>93</td>
    </tr>
  </tbody>
</table>
</div>




```
# cov from pandas
df.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>amounts</th>
      <th>customers</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>amounts</th>
      <td>242557.904762</td>
      <td>8073.642857</td>
    </tr>
    <tr>
      <th>customers</th>
      <td>8073.642857</td>
      <td>290.952381</td>
    </tr>
  </tbody>
</table>
</div>




```

```

## 1.3 Find the standard deviation of customers who entered the store last week. Then, use the standard deviations of both sales and customers to standardize the covariance to find the correlation coefficient that summarizes the relationship between sales and customers. (You may use library functions to check your work.)


```
# standard deviation of customers & sales amount
std_c = df['customers'].std(ddof=1)
std_a = df['amounts'].std(ddof=1)
std_c, std_a
```




    (17.057326313123664, 492.5016799584595)




```
# covariance with pandas
cov_ac = df['amounts'].cov(df['customers'])
cov_ac
```




    8073.642857142856




```
denom = std_a*std_c
denom
```




    8400.761864813041




```
# correlation
corr_ac = cov_ac/denom
corr_ac
```




    0.9610607927073451




```
df['amounts'].corr(df['customers'])
```




    0.9610607927073453




```
df.corr()
```




<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>amounts</th>
      <th>customers</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>amounts</th>
      <td>1.000000</td>
      <td>0.961061</td>
    </tr>
    <tr>
      <th>customers</th>
      <td>0.961061</td>
      <td>1.000000</td>
    </tr>
  </tbody>
</table>
</div>



## 1.4 Use pandas to import a cleaned version of the titanic dataset from the following link: [Titanic Dataset](https://raw.githubusercontent.com/Geoyi/Cleaning-Titanic-Data/master/titanic_clean.csv)

## Calculate the variance-covariance matrix and correlation matrix for the titanic dataset's numeric columns. (you can encode some of the categorical variables and include them as a stretch goal if you finish early)


```
url = 'https://raw.githubusercontent.com/Geoyi/Cleaning-Titanic-Data/master/titanic_clean.csv'
titanic = pd.read_csv(url, index_col=0)
titanic.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>pclass</th>
      <th>survived</th>
      <th>name</th>
      <th>sex</th>
      <th>age</th>
      <th>sibsp</th>
      <th>parch</th>
      <th>ticket</th>
      <th>fare</th>
      <th>cabin</th>
      <th>embarked</th>
      <th>boat</th>
      <th>body</th>
      <th>home.dest</th>
      <th>has_cabin_number</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th>
      <td>1.0</td>
      <td>1.0</td>
      <td>Allen, Miss. Elisabeth Walton</td>
      <td>female</td>
      <td>29.0000</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>24160</td>
      <td>211.3375</td>
      <td>B5</td>
      <td>S</td>
      <td>2</td>
      <td>NaN</td>
      <td>St Louis, MO</td>
      <td>1</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.0</td>
      <td>1.0</td>
      <td>Allison, Master. Hudson Trevor</td>
      <td>male</td>
      <td>0.9167</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>113781</td>
      <td>151.5500</td>
      <td>C22 C26</td>
      <td>S</td>
      <td>11</td>
      <td>NaN</td>
      <td>Montreal, PQ / Chesterville, ON</td>
      <td>1</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.0</td>
      <td>0.0</td>
      <td>Allison, Miss. Helen Loraine</td>
      <td>female</td>
      <td>2.0000</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>113781</td>
      <td>151.5500</td>
      <td>C22 C26</td>
      <td>S</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>Montreal, PQ / Chesterville, ON</td>
      <td>1</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1.0</td>
      <td>0.0</td>
      <td>Allison, Mr. Hudson Joshua Creighton</td>
      <td>male</td>
      <td>30.0000</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>113781</td>
      <td>151.5500</td>
      <td>C22 C26</td>
      <td>S</td>
      <td>NaN</td>
      <td>135.0</td>
      <td>Montreal, PQ / Chesterville, ON</td>
      <td>1</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.0</td>
      <td>0.0</td>
      <td>Allison, Mrs. Hudson J C (Bessie Waldo Daniels)</td>
      <td>female</td>
      <td>25.0000</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>113781</td>
      <td>151.5500</td>
      <td>C22 C26</td>
      <td>S</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>Montreal, PQ / Chesterville, ON</td>
      <td>1</td>
    </tr>
  </tbody>
</table>
</div>




```
# covariance for the entire dataset
titanic.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>pclass</th>
      <th>survived</th>
      <th>age</th>
      <th>sibsp</th>
      <th>parch</th>
      <th>fare</th>
      <th>body</th>
      <th>has_cabin_number</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>pclass</th>
      <td>0.701969</td>
      <td>-0.127248</td>
      <td>-3.954605</td>
      <td>0.053090</td>
      <td>0.013287</td>
      <td>-24.227788</td>
      <td>-2.876653</td>
      <td>-0.249992</td>
    </tr>
    <tr>
      <th>survived</th>
      <td>-0.127248</td>
      <td>0.236250</td>
      <td>-0.314343</td>
      <td>-0.014088</td>
      <td>0.034776</td>
      <td>6.146023</td>
      <td>0.000000</td>
      <td>0.061406</td>
    </tr>
    <tr>
      <th>age</th>
      <td>-3.954605</td>
      <td>-0.314343</td>
      <td>165.850021</td>
      <td>-2.559806</td>
      <td>-1.459378</td>
      <td>114.416613</td>
      <td>81.622922</td>
      <td>1.463138</td>
    </tr>
    <tr>
      <th>sibsp</th>
      <td>0.053090</td>
      <td>-0.014088</td>
      <td>-2.559806</td>
      <td>1.085052</td>
      <td>0.336833</td>
      <td>8.641768</td>
      <td>-8.708471</td>
      <td>-0.003946</td>
    </tr>
    <tr>
      <th>parch</th>
      <td>0.013287</td>
      <td>0.034776</td>
      <td>-1.459378</td>
      <td>0.336833</td>
      <td>0.749195</td>
      <td>9.928031</td>
      <td>4.237190</td>
      <td>0.013316</td>
    </tr>
    <tr>
      <th>fare</th>
      <td>-24.227788</td>
      <td>6.146023</td>
      <td>114.416613</td>
      <td>8.641768</td>
      <td>9.928031</td>
      <td>2678.959738</td>
      <td>-179.164684</td>
      <td>10.976961</td>
    </tr>
    <tr>
      <th>body</th>
      <td>-2.876653</td>
      <td>0.000000</td>
      <td>81.622922</td>
      <td>-8.708471</td>
      <td>4.237190</td>
      <td>-179.164684</td>
      <td>9544.688567</td>
      <td>3.625689</td>
    </tr>
    <tr>
      <th>has_cabin_number</th>
      <td>-0.249992</td>
      <td>0.061406</td>
      <td>1.463138</td>
      <td>-0.003946</td>
      <td>0.013316</td>
      <td>10.976961</td>
      <td>3.625689</td>
      <td>0.174613</td>
    </tr>
  </tbody>
</table>
</div>




```
titanic.corr()
```




<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>pclass</th>
      <th>survived</th>
      <th>age</th>
      <th>sibsp</th>
      <th>parch</th>
      <th>fare</th>
      <th>body</th>
      <th>has_cabin_number</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>pclass</th>
      <td>1.000000</td>
      <td>-0.312469</td>
      <td>-0.366370</td>
      <td>0.060832</td>
      <td>0.018322</td>
      <td>-0.558629</td>
      <td>-0.034642</td>
      <td>-0.713857</td>
    </tr>
    <tr>
      <th>survived</th>
      <td>-0.312469</td>
      <td>1.000000</td>
      <td>-0.050199</td>
      <td>-0.027825</td>
      <td>0.082660</td>
      <td>0.244265</td>
      <td>NaN</td>
      <td>0.302250</td>
    </tr>
    <tr>
      <th>age</th>
      <td>-0.366370</td>
      <td>-0.050199</td>
      <td>1.000000</td>
      <td>-0.190747</td>
      <td>-0.130872</td>
      <td>0.171892</td>
      <td>0.059059</td>
      <td>0.271887</td>
    </tr>
    <tr>
      <th>sibsp</th>
      <td>0.060832</td>
      <td>-0.027825</td>
      <td>-0.190747</td>
      <td>1.000000</td>
      <td>0.373587</td>
      <td>0.160238</td>
      <td>-0.099961</td>
      <td>-0.009064</td>
    </tr>
    <tr>
      <th>parch</th>
      <td>0.018322</td>
      <td>0.082660</td>
      <td>-0.130872</td>
      <td>0.373587</td>
      <td>1.000000</td>
      <td>0.221539</td>
      <td>0.051099</td>
      <td>0.036806</td>
    </tr>
    <tr>
      <th>fare</th>
      <td>-0.558629</td>
      <td>0.244265</td>
      <td>0.171892</td>
      <td>0.160238</td>
      <td>0.221539</td>
      <td>1.000000</td>
      <td>-0.043110</td>
      <td>0.507253</td>
    </tr>
    <tr>
      <th>body</th>
      <td>-0.034642</td>
      <td>NaN</td>
      <td>0.059059</td>
      <td>-0.099961</td>
      <td>0.051099</td>
      <td>-0.043110</td>
      <td>1.000000</td>
      <td>0.083796</td>
    </tr>
    <tr>
      <th>has_cabin_number</th>
      <td>-0.713857</td>
      <td>0.302250</td>
      <td>0.271887</td>
      <td>-0.009064</td>
      <td>0.036806</td>
      <td>0.507253</td>
      <td>0.083796</td>
      <td>1.000000</td>
    </tr>
  </tbody>
</table>
</div>




```
# heatmap
import seaborn as sns
sns.heatmap(titanic.corr());
```

# Orthogonality

## 2.1 Plot two vectors that are orthogonal to each other. What is a synonym for orthogonal?


```
# orthogonal is perpendicular (having a right angle)
import matplotlib.pyplot as plt
vector_1 = [0, 3]
vector_2 = [-4, 0]
```


```
fig, ax = plt.subplots(figsize=(5,5))
ax.grid()
plt.xlim(-5, 5)
plt.ylim(-5, 5)
for vect in [vector_1, vector_2]:
  plt.arrow(0,0, vect[0], vect[1], head_width=.2, head_length=0.2, linewidth=4)
plt.show()
```


```
# check if orthogonal, dot product must be == 0
np.dot(vector_1, vector_2)
```




    0



## 2.2 Are the following vectors orthogonal? Why or why not?

\begin{align}
a = \begin{bmatrix} -5 \\ 3 \\ 7 \end{bmatrix}
\qquad
b = \begin{bmatrix} 6 \\ -8 \\ 2 \end{bmatrix}
\end{align}


```
a = np.array([-5,3,7])
b = np.array([6,-8,2])
np.dot(a,b)
# no because the dot product does not equal to 0
```




    -40



## 2.3 Compute the following values: What do these quantities have in common?

## What is $||c||^2$? 

## What is $c \cdot c$? 

## What is $c^{T}c$?

\begin{align}
c = \begin{bmatrix} 2 & -15 & 6 & 20 \end{bmatrix}
\end{align}


```
c = np.array([2, -15, 6, 20])
c
```




    array([  2, -15,   6,  20])




```
c_squared = list(map(lambda x: x**2, c))
c_squared
```




    [4, 225, 36, 400]




```
cxc = np.multiply(c,c)
cxc
```




    array([  4, 225,  36, 400])




```
cT = c.T
cTc = np.multiply(cT, c)
print(cT)
cTc
```

    [  2 -15   6  20]





    array([  4, 225,  36, 400])




```
# all quantities yield to same resultts
```

# Unit Vectors

## 3.1 Using Latex, write the following vectors as a linear combination of scalars and unit vectors:

\begin{align}
d = \begin{bmatrix} 7 \\ 12 \end{bmatrix}
\qquad
e = \begin{bmatrix} 2 \\ 11 \\ -8  \end{bmatrix}
\end{align}

\begin{table}[]
\begin{tabular}{|l|l|}
\hline
vector d & vector e \\ \hline
7        & 2        \\ \hline
12       & 11       \\ \hline
         & -8       \\ \hline
\end{tabular}
\end{table}

## 3.2 Turn vector $f$ into a unit vector:

\begin{align}
f = \begin{bmatrix} 4 & 12 & 11 & 9 & 2 \end{bmatrix}
\end{align}


```
# unit vector
f = np.array([4, 12 ,11, 9, 2])
f_hat = f/np.linalg.norm(f)
print(f)
f_hat
```

    [ 4 12 11  9  2]





    array([0.20908335, 0.62725005, 0.57497921, 0.47043754, 0.10454167])



# Linear Independence / Dependence 

## 4.1 Plot two vectors that are linearly dependent and two vectors that are linearly independent (bonus points if done in $\mathbb{R}^3$).


```
# linear dependent vectors
vector_01 = [1.5, -.7]
vector_02 = np.multiply(vector_01, 2)
vector_01, vector_02
```




    ([1.5, -0.7], array([ 3. , -1.4]))




```
# plot
fig, ax = plt.subplots(figsize=(4,4))
ax.grid()
plt.xlim(-4, 4)
plt.ylim(-4, 4)
for myvect, mycolor, mywidth in [(vector_01, 'blue', 15), (vector_02, 'red', 5)]:
  plt.arrow(0,0,
            myvect[0],
            myvect[1],
            head_width=.2,
            head_length=.2,
            linewidth=mywidth,
            color=mycolor,
            length_includes_head=True);
```


```
# linearly independent
vector_01 = [1.5, -.7]
vector_03 = [-2, -1.3]
vector_01, vector_03
```




    ([1.5, -0.7], [-2, -1.3])




```
fig, ax = plt.subplots(figsize=(4,4))
ax.grid()
plt.xlim(-4, 4)
plt.ylim(-4, 4)
for myvect, mycolor, mywidth in [(vector_01, 'blue', 15), (vector_03, 'yellow', 5)]:
  plt.arrow(0,0,
            myvect[0],
            myvect[1],
            head_width=.2,
            head_length=.2,
            linewidth=mywidth,
            color=mycolor,
            length_includes_head=True);
```


```

```

# Span

## 5.1 What is the span of the following vectors?

\begin{align}
g = \begin{bmatrix} 1 & 2 \end{bmatrix}
\qquad
h = \begin{bmatrix} 4 & 8 \end{bmatrix}
\end{align}


```
vector_g = np.array([1, 2])
vector_h = np.array([4, 8])
fig, ax = plt.subplots(figsize=(4,4))
ax.grid()
plt.xlim(0,10)          
plt.ylim(0,10)

# Display
for myvect in [vector_g, vector_h]:
    plt.arrow(0,0,
              myvect[0], 
              myvect[1], 
              head_width=.2, 
              head_length=0.2, 
              linewidth=5, 
              color='magenta')
```


```
# possible linear combination
a,b=(4,2)
linear_combo=np.multiply(vector_g, a) + np.multiply(vector_g, b)
print(linear_combo)
```

    [ 6 12]



```
combo_sets=[]
for (a,b) in [(2,3), (4,5), (6,7), (8,9)]:
  linear_combo = np.multiply(vector_1, a) + np.multiply(vector_2, b) 
  combo_sets.append(linear_combo)
print(combo_sets)
```

    [array([-12,   6]), array([-20,  12]), array([-28,  18]), array([-36,  24])]


## 5.2 What is the span of $\{l, m, n\}$?

\begin{align}
l = \begin{bmatrix} 1 & 2 & 3 \end{bmatrix}
\qquad
m = \begin{bmatrix} -1 & 0 & 7 \end{bmatrix}
\qquad
n = \begin{bmatrix} 4 & 8  & 2\end{bmatrix}
\end{align}


```
vector_l = np.array([1,2,3])
vector_m = np.array([-1,0,7])
vector_n = np.array([4,8,2])

```


```
a,b,c = (2,3,4)
linear_com = np.multiply(vector_l, a) + np.multiply(vector_m, b) + np.multiply(vector_n, c)
print(linear_com)
```

    [15 36 35]


# Basis

## 6.1 Graph two vectors that form a basis for $\mathbb{R}^2$




```
# find basis vectors in 2-d
vector_1 = [0, 3]
vector_2 = [2, 0]

# Plot the Scaled Vectors
plt.arrow(0,0, vector_1[0], vector_1[1],head_width=.05, head_length=0.05, color ='purple')
plt.arrow(0,0, vector_2[0], vector_2[1],head_width=.05, head_length=0.05, color ='navy')
plt.xlim(-3,3)          
plt.ylim(-1,4)
plt.title("Basis for R^2")
plt.show()
```

## 6.2 What does it mean to form a basis?

form a family of linearly independent vectors which spans a given vector space

# Rank

## 7.1 What is the Rank of P?

\begin{align}
P = \begin{bmatrix} 
1 & 2 & 3 \\
 -1 & 0 & 7 \\
4 & 8  & 2
\end{bmatrix}
\end{align}


```
# rank 3
P = np.array([[1,2,3],[-1,0,7],[4,8,2]])
np.linalg.matrix_rank(P)
```




    3



## 7.2 What does the rank of a matrix tell us?

Rank means the number of dimensions in the output of a matrix that's used for linear transformation.

# Linear Projections

## 8.1 Line $L$ is formed by all of the vectors that can be created by scaling vector $v$ 
\begin{align}
v = \begin{bmatrix} 1 & 3 \end{bmatrix}
\end{align}

\begin{align}
w = \begin{bmatrix} -1 & 2 \end{bmatrix}
\end{align}

## find $proj_{L}(w)$

## graph your projected vector to check your work (make sure your axis are square/even)


```
# vectors
v = np.array([1,3])
w = np.array([-1,2])
# dot product
w_dot_v = np.dot(v, w)
v_dot_v = np.dot(v, v)
#projection
fraction = w_dot_v/v_dot_v
projection = np.multiply(fraction,v)
print(projection)
```

    [0.5 1.5]



```
# Plot
plt.xlim(0,4)          
plt.ylim(0,4)

axes = plt.gca()
plt.axes().set_aspect('equal')
plt.plot(v, w, '--', color='orange', linewidth=1);
```

# Stretch Goal

## For vectors that begin at the origin, the coordinates of where the vector ends can be interpreted as regular data points. (See 3Blue1Brown videos about Spans, Basis, etc.)

## Write a function that can calculate the linear projection of each point (x,y) (vector) onto the line y=x. run the function and plot the original points in blue and the new projected points on the line y=x in red. 

## For extra points plot the orthogonal vectors as a dashed line from the original blue points to the projected red points.


```
import pandas as pd
import matplotlib.pyplot as plt

# Creating a dataframe for you to work with -Feel free to not use the dataframe if you don't want to.
x_values = [1, 4, 7, 3, 9, 4, 5 ]
y_values = [4, 2, 5, 0, 8, 2, 8]

data = {"x": x_values, "y": y_values}

df = pd.DataFrame(data)

df.head()

plt.scatter(df.x, df.y)
plt.show()
```


```

```

dd33cb643204f180a745389340e9309f4a33b46d
ipynb
Jupyter Notebook
01_Unit_1/Sprint3-Linear-Algebra/Module2/LS_DS_132_Intermediate_Linear_Algebra_Assignment.ipynb
mark-morelos/my_DataScience_notes
2e05a3d77949cb8ccd9aac7c04cf7758d7b73d1c
MIT
01_Unit_1/Sprint3-Linear-Algebra/Module2/LS_DS_132_Intermediate_Linear_Algebra_Assignment.ipynb
mark-morelos/my_DataScience_notes
2e05a3d77949cb8ccd9aac7c04cf7758d7b73d1c
MIT
01_Unit_1/Sprint3-Linear-Algebra/Module2/LS_DS_132_Intermediate_Linear_Algebra_Assignment.ipynb
mark-morelos/my_DataScience_notes
2e05a3d77949cb8ccd9aac7c04cf7758d7b73d1c
MIT
Qwen/Qwen-72B
1. YES
2. YES