More work on multivariate gaussians.
Not copy edited yet, but more work on making the material on multivariate gaussian more understandable (mostly by reordering concepts).
This commit is contained in:
@@ -37,6 +37,24 @@ def plot_height_std(x, lw=10):
|
||||
plt.show()
|
||||
|
||||
|
||||
def plot_correlated_data(X, Y, xlabel=None,
|
||||
ylabel=None, equal=True):
|
||||
|
||||
plt.scatter(X, Y)
|
||||
|
||||
if xlabel is not None:
|
||||
plt.xlabel('Height (in)');
|
||||
|
||||
if ylabel is not None:
|
||||
plt.ylabel('Weight (lbs)')
|
||||
|
||||
# fit line through data
|
||||
m, b = np.polyfit(X, Y, 1)
|
||||
plt.plot(X, np.asarray(X)*m + b,color='k')
|
||||
if equal:
|
||||
plt.gca().set_aspect('equal')
|
||||
plt.show()
|
||||
|
||||
def plot_gaussian (mu, variance,
|
||||
mu_line=False,
|
||||
xlim=None,
|
||||
|
||||
@@ -404,12 +404,16 @@ def plot_3_covariances():
|
||||
|
||||
P = [[2, 0], [0, 2]]
|
||||
plt.subplot(131)
|
||||
plt.gca().grid(b=False)
|
||||
plt.gca().set_xticks([0,1,2,3,4])
|
||||
plot_covariance_ellipse((2, 7), cov=P, facecolor='g', alpha=0.2,
|
||||
title='|2 0|\n|0 2|', axis_equal=False)
|
||||
plt.ylim((4, 10))
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
|
||||
plt.subplot(132)
|
||||
plt.gca().grid(b=False)
|
||||
plt.gca().set_xticks([0,1,2,3,4])
|
||||
P = [[2, 0], [0, 9]]
|
||||
plt.ylim((4, 10))
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
@@ -417,6 +421,8 @@ def plot_3_covariances():
|
||||
axis_equal=False, title='|2 0|\n|0 9|')
|
||||
|
||||
plt.subplot(133)
|
||||
plt.gca().grid(b=False)
|
||||
plt.gca().set_xticks([0,1,2,3,4])
|
||||
P = [[2, 1.2], [1.2, 2]]
|
||||
plt.ylim((4, 10))
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
@@ -437,7 +443,7 @@ def plot_correlation_covariance():
|
||||
plt.gca().autoscale(tight=True)
|
||||
plt.axvline(7.5, ls='--', lw=1)
|
||||
plt.axhline(12.5, ls='--', lw=1)
|
||||
plt.scatter(7.5, 12.5, s=2000, alpha=0.5)
|
||||
plt.scatter(7.5, 12.5, s=1500, alpha=0.5)
|
||||
plt.title('|4.0 3.9|\n|3.9 4.0|')
|
||||
plt.show()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user