diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2015-11-16 12:35:05 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2015-11-16 12:35:05 -0500 |
| commit | adc7cb7256c8fcc11e7fd85866d6d3e2dcb319c1 (patch) | |
| tree | 9b0065b6215919e86fc0ea3f377ea6bf536b4bf2 /hw4/plot.py | |
| parent | 61f644a6a7d36dc5c15d957c48d10675ab3627ae (diff) | |
| download | cs281-adc7cb7256c8fcc11e7fd85866d6d3e2dcb319c1.tar.gz | |
Diffstat (limited to 'hw4/plot.py')
| -rw-r--r-- | hw4/plot.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/hw4/plot.py b/hw4/plot.py new file mode 100644 index 0000000..0ed704a --- /dev/null +++ b/hw4/plot.py @@ -0,0 +1,45 @@ +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sbn + +sbn.set_style("white") + + +def three(): + with open("gibbs_2.txt") as fh: + values = [map(float, line.strip().split()) for line in fh] + a, b, c = zip(*values) + plt.figure(figsize=(8, 6)) + plt.plot(a, -np.array(b), label="train") + plt.plot(a, -np.array(c), label="test") + plt.legend(loc="lower right") + plt.xlabel("Epoch") + plt.ylabel("Likelihood") + plt.savefig("2.pdf") + + +def four(): + plt.figure(figsize=(8, 6)) + for i in xrange(1, 11): + with open("gibbs_" + str(i) + ".txt") as fh: + values = [map(float, line.strip().split()) for line in fh] + a, b, c = zip(*values) + plt.plot(a, np.array(b), label="K=" + str(i)) + plt.legend(loc="upper right") + plt.xlabel("Epoch") + plt.ylabel("MSE") + plt.axes().set_yscale("log") + plt.savefig("train.pdf") + + plt.figure(figsize=(8, 6)) + for i in xrange(1, 11): + with open("gibbs_" + str(i) + ".txt") as fh: + values = [map(float, line.strip().split()) for line in fh] + a, b, c = zip(*values) + plt.plot(a, np.array(c), label="K=" + str(i)) + plt.legend(loc="upper right") + plt.xlabel("Epoch") + plt.ylabel("MSE") + plt.axes().set_yscale("log") + plt.savefig("test.pdf") +four() |
