## Mathematics for Machine Learning: Linear Algebra Mathematics for Machine Learning: Linear Algebra by Imperial College London on Coursera. Certificate earned at Wednesday, January 16, 2019 7:32 PM GMT as part of the pre-work requirements for CodeUp’s Data Science Career Accelerator program.

## Gram-Schmidt

According to Wikipedia,

the GramSchmidt process is a method for orthonormalising a set of vectors in an inner product space,

Gram–Schmidt process, Wikipedia

Orthonormalising?

Not only is it “right,” it also makes your life a whole lot easier. If you don’t believe me, just watch the video on Coursera or have a go at it with our best friend, Salman Khan on Khan Academy.

We had to automate the process by writing a Python application. I”m not sure what I like best, learning about it, or coding about it. Me thinks I’ll take the latter.

Here’s a snippet:

```def gsBasis(A) :
B = np.array(A, dtype=np.float_)
for i in range(B.shape) :
for j in range(i) :
B[:, i] = B[:,i] - B[:,i] @ B[:,j] * B[:,j]
if la.norm(B[:, i]) > verySmallNumber :
B[:, i] = B[:, i] / la.norm(B[:, i])
else :
B[:, i] = np.zeros_like(B[:, i])
return B```

You can view the full code on Github.

## Special Matrices

In Coursera’s Mathematics for Machine Learning: Linear Algebra class, we learned all about matrices. One of my favorite is the row echelon form or REF.

I like it ‘cuz it sounds fancy and Trekkie-like.

Anyways, we had to write a Python application that converts a 4×4 matrix into row echelon form. There’s also a feature in there that catches errors in case of extra special matrices like singular matrices.

```def fixRowTwo(A) :
A = A - A * A[2,0]
A = A - A * A[2,1]
if A[2,2] == 0 :
A = A + A
A = A - A * A[2,0]
A = A - A * A[2,1]
if A[2,2] == 0 :
raise MatrixIsSingular()
A = A / A[2,2]
return A```

You can view the full code on Github.