import matplotlib.pyplot as plt
from collections import Counter
c = Counter((w for l in open("train.txt") for w in l.strip().split() if w != "<unk>"))
%matplotlib inline
import numpy as np
ls = np.array([n for _, n in c.most_common(1000)])
words = [w for w, _ in c.most_common(1000)]
#plt.plot(ls[:200])
sns.set_context("talk", rc={"lines.linewidth": 2.5})
sns.set_style("darkgrid")
f, ax = plt.subplots(figsize=(10, 7))
#plt.plot(figsize=(10,10))
sns.barplot(x="total", y="abbrev", data={"total": ls[:200], "abbrev": words[:200]},
label="Total")
_ = ax.set_yticklabels([ w if i % 10 ==0 else "" for i, w in enumerate(words[:200]) ])
plt.savefig("zipf.png")
/usr/local/lib/python3.4/dist-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter. warnings.warn(self.msg_depr % (key, alt_key))
import seaborn as sns
y
array([-1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -1. , -0.99999997, -0.99999856, -0.99991793, -0.99534489, -0.76580379, 0.76580379, 0.99534489, 0.99991793, 0.99999856, 0.99999997, 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ])
x = np.linspace(-5, 5, 1000)
y = np.tanh(x)
plt.plot(x, y)
#sns.regplot(y="y", x="x", data={"x":x, "y":y}, scatter=False, order=5)
plt.savefig("tanh.png")
x = np.linspace(-5, 5, 1000)
y = np.array([max(a, 0) for a in list(x)])
plt.plot(x, y)
#sns.regplot(y="y", x="x", data={"x":x, "y":y}, scatter=False, order=5)
plt.savefig("Relu.png")