08 Example - Transforming a discrete random variable
08 Example - Transforming a discrete random variable#
%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/nb3m_Q7rfT4/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
x_df = DataFrame({
'X = # of makes': [0, 1, 2],
'P(x)': [0.16, 0.48, 0.36]
})
y_df = DataFrame()
y_df['N = netgain'] = x_df['X = # of makes'] * 10 - 15
y_df['P(x)'] = x_df['P(x)']
mu_x = np.sum(x_df['X = # of makes'] * x_df['P(x)'])
mu_y = np.sum(y_df['N = netgain'] * y_df['P(x)'])
var_x = np.sum((x_df['X = # of makes'] - mu_x)**2 * x_df['P(x)'])
var_y = np.sum((y_df['N = netgain'] - mu_y)**2 * y_df['P(x)'])
std_x = np.sqrt(var_x)
std_y = np.sqrt(var_y)
print(mu_x, mu_y, var_x, var_y, std_x, std_y)
1.2 -3.0 0.48000000000000004 48.0 0.6928203230275509 6.928203230275509
mu_y == 10 * mu_x - 15
True
std_y == 10 * std_x
True