Skip to content

Instantly share code, notes, and snippets.

View hadrienj's full-sized avatar

Hadrien Jean hadrienj

View GitHub Profile
@hadrienj
hadrienj / utils_essential_math_data_science.py
Last active April 18, 2021 11:28
Utils functions used in the book `Essential Math for Data Science` ( more details here: https://bit.ly/32oQugr).
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.collections as mcoll
def matrix_2d_effect(transfo_matrix, vectorsCol=["#FFD800", "#00CD79"]):
"""
Modify the unit circle and basis vector by applying a matrix.
Visualize the effect of the matrix in 2D.
@hadrienj
hadrienj / unit_vectors.py
Created April 9, 2020 09:25
Plot unit vectors
# choose figure size
plt.figure(figsize=(6, 6))
# Assure that ticks are displayed with a step equal to 1
ax = plt.gca()
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
# draw axes
plt.axhline(0, c='#A9A9A9', zorder=0)
plotImage(X[12, :])
plotImage(X_ZCA_rescaled[12, :])
X_ZCA_rescaled = (X_ZCA - X_ZCA.min()) / (X_ZCA.max() - X_ZCA.min())
print 'min:', X_ZCA_rescaled.min()
print 'max:', X_ZCA_rescaled.max()
epsilon = 0.1
X_ZCA = U.dot(np.diag(1.0/np.sqrt(S + epsilon))).dot(U.T).dot(X_norm)
plotImage(X[12, :])
plotImage(X_ZCA[12, :])
print np.diag(S)
print '\nshape:', np.diag(S).shape