05 How parameters change as data is shifted and scaled#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/JFlI4Vxtzxo/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
from scipy import stats

khanacademy

How parameters change as data is shifted and scaled fig 1

x = np.array([7, 7, 5, 8, 10, 13, 5, 3, 2, 3, 5, 6])
df = DataFrame({'Data': x, 
               'Data+5': x+5,
               'Data*5': x*5})
df
Data Data+5 Data*5
0 7 12 35
1 7 12 35
2 5 10 25
3 8 13 40
4 10 15 50
5 13 18 65
6 5 10 25
7 3 8 15
8 2 7 10
9 3 8 15
10 5 10 25
11 6 11 30
mean_std_df = df.describe()[1:3]
median_iqr_df = DataFrame({'Data': [np.median(df['Data']), stats.iqr(df['Data'])],
 'Data+5': [np.median(df['Data+5']), stats.iqr(df['Data+5'])],
 'Data*5': [np.median(df['Data*5']), stats.iqr(df['Data*5'])]
}, index=['median', 'iqr'])
df = pd.concat([df, mean_std_df, median_iqr_df])
df
Data Data+5 Data*5
0 7.000000 12.000000 35.000000
1 7.000000 12.000000 35.000000
2 5.000000 10.000000 25.000000
3 8.000000 13.000000 40.000000
4 10.000000 15.000000 50.000000
5 13.000000 18.000000 65.000000
6 5.000000 10.000000 25.000000
7 3.000000 8.000000 15.000000
8 2.000000 7.000000 10.000000
9 3.000000 8.000000 15.000000
10 5.000000 10.000000 25.000000
11 6.000000 11.000000 30.000000
mean 6.166667 11.166667 30.833333
std 3.128559 3.128559 15.642793
median 5.500000 10.500000 27.500000
iqr 2.750000 2.750000 13.750000
df[-4:]
Data Data+5 Data*5
mean 6.166667 11.166667 30.833333
std 3.128559 3.128559 15.642793
median 5.500000 10.500000 27.500000
iqr 2.750000 2.750000 13.750000