import numpy
import scipy
import matplotlib
import sklearn
import psutil
import pandas
import IPython.parallel
Finding the location of an installed package and its version:
numpy.__path__
numpy.__version__
%run ../fetch_data.py
# %run ../fetch_data.py twenty_newsgroups sentiment140 covertype
import os
for fname in os.listdir('../datasets/'):
print(fname)
import numpy as np
a = np.array([1, 2, 3])
a
b = np.array([[0, 2, 4], [1, 3, 5]])
b
b.shape
b.dtype
a.shape
a.dtype
np.zeros(5)
np.ones(shape=(3, 4), dtype=np.int32)
c = b * 0.5
c
c.shape
c.dtype
a
d = a + c
d
d[0]
d[0, 0]
d[:, 0]
d.sum()
d.mean()
d.sum(axis=0)
d.mean(axis=1)
e = np.arange(12)
e
f = e.reshape(3, 4)
f
e
e[5:] = 0
e
f
a
b
d
np.concatenate([a, a, a])
np.vstack([a, b, d])
np.hstack([b, d])
%matplotlib inline
import matplotlib.pyplot as plt
x = np.linspace(0, 2, 10)
x
plt.plot(x, 'o-');
plt.plot(x, x, 'o-', label='linear')
plt.plot(x, x ** 2, 'x-', label='quadratic')
plt.legend(loc='best')
plt.title('Linear vs Quadratic progression')
plt.xlabel('Input')
plt.ylabel('Output');
samples = np.random.normal(loc=1.0, scale=0.5, size=1000)
samples.shape
samples.dtype
samples[:30]
plt.hist(samples, bins=50);
samples_1 = np.random.normal(loc=1, scale=.5, size=10000)
samples_2 = np.random.standard_t(df=10, size=10000)
bins = np.linspace(-3, 3, 50)
_ = plt.hist(samples_1, bins=bins, alpha=0.5, label='samples 1')
_ = plt.hist(samples_2, bins=bins, alpha=0.5, label='samples 2')
plt.legend(loc='upper left');
plt.scatter(samples_1, samples_2, alpha=0.1);