<jupyter_start><jupyter_text>2.3.1 Basic Command<jupyter_code># vector x
x = np.array([1, 3, 2, 5])
x
x = np.array([1, 6, 2])
y = np.array([1, 4, 3])
x, y
x.shape, y.shape
x.size, y.size
x + y
x = np.matrix([[1, 2], [3, 4]])
x
np.sqrt(x)
# x * x
x ** 2
# x .* x
np.square(x)
x = np.random.normal(size=50)
x
# loc is mean, scale is std
y = x + np.random.normal(loc=50, scale=.1, size=50)
y
np.corrcoef(x, y)<jupyter_output><empty_output><jupyter_text>2.3.2 Graphics<jupyter_code>x = np.random.normal(size=100)
y = np.random.normal(size=100)
plt.scatter(x, y)
plt.xlabel('x', fontsize=12)
plt.ylabel('y', fontsize=12)
plt.title('Plot of X vs Y')
plt.show()
x = np.arange(1,10)
x
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)

plt.figure()
CS = plt.contour(X, Y, Z)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')
plt.show()<jupyter_output><empty_output><jupyter_text>2.3.3 Indexing Data<jupyter_code>A = np.arange(1, 17).reshape(4, 4).T
A
A[1, 2]
# This is so fancy...
# https://stackoverflow.com/questions/22927181/selecting-specific-rows-and-columns-from-numpy-array

# A[[[0], [2]],[1, 3]]
# odd rows, even columns
A[[[x] for x in range(0, A.shape[1], 2)],[x for x in range(1, A.shape[1], 2)]]
A[:3][:,1:]
A[:2]
A[:2,:2]<jupyter_output><empty_output><jupyter_text>2.3.4 Loading Data<jupyter_code>df = pd.read_csv('../data/Auto.csv')
df.head()
df.shape
df.columns<jupyter_output><empty_output><jupyter_text>2.3.5 Additional Graphical and Numerical Summaries<jupyter_code>plt.scatter(df['cylinders'], df['mpg'])
plt.xlabel('cylinders', fontsize=12)
plt.ylabel('mpg', fontsize=12)
plt.title('Plot of cylinders vs mpg')
plt.show()
plt.hist(df['mpg'], bins=20)
plt.show()
df.describe()
df['mpg'].describe()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21269035532994923, 'fraction_numerical': 0.06192893401015229, 'mean_word_length': 5.064615384615385, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '454084', 'license': 'MIT', 'n_tokens_mistral': 1006, 'n_tokens_neox': 917, 'n_words': 188, 'path': 'labs/Chapter 2 - Statistical Learning.ipynb', 'repo_name': 'KeshavRDudhe/islr', 'size': '1970'}