Linear Algebra for Machine Learning A-Z – DataDrivenInvestor

npressfetimg-12298.png

Briefly Explained with Python Codes

Photo by Roman Mager on Unsplash

Content Table· Introduction
· Linear Transformation
· Vectors and Operations
∘ 1 Dimensional Vector
∘ 2 Dimensional Vector
∘ 3 Dimensional Vector
∘ Scaling
∘ Scaling Formula
∘ Scaling Python Implementation
∘ Scaler
∘ L1 Norm
∘ L2 Norm
∘ L2 Norm Formula
∘ L2 Norm Python Implementation
∘ Vector Multiplication
∘ Vector Multiplication Formula
∘ Vector Multiplication Python Implementation
∘ Vector Dot Operation
∘ Vector Dot Formula
∘ Vector Dot Python Implementation
· Matrix Operations
∘ Vector Matrix Multipication
∘ Vector Matrix Multiplication Formula
∘ Vector Matrix Python Implementation
∘ Matrix Scalar Multiplication
∘ Matrix Scalar Multiplication Formula
∘ Matrix Scalar Multiplication Python Implementation
∘ Matrix Matrix Multiplication
∘ Matrix-Matrix Multiplication Formula
∘ Matrix-Matrix Multiplication Python Implementation
∘ Matrix Transpose
∘ Matrix Transpose Formula
∘ Matrix Transpose Python Implementation
∘ Matrix Inverse
∘ Matrix Inverse Formula
∘ Matrix Inverse Python Implementation
∘ Matrix Determinant
∘ Matrix Determinant Python Implementation
· Special Matrices
∘ Square Matrix
∘ Square Matrix Python Implementation
∘ Identity Matrix
∘ Identity Matrix Python Implementation
∘ Orthogonal Matrix
∘ Orthogonal Matrix Formula
∘ Diagonal Matrix
∘ Diagonal Matrix Formula
∘ Diagonal Matrix Python Implementation
· Reshaping Dimension
∘ 1D to 2D
∘ 1D to 2D Python Implementation
∘ 2D to 3D
∘ 2D to 3D Python Implementation
· Conclusion

Hi to all.

In this article, I try to indicate to you guys Linear Algebra terms, briefly.

There are tons of really good videos and books, which will explain Linear Algebra A-Z.

In my opinion, one of the most valuable ones is the following;

Now, I took the class linear algebra at University, that’s why I already had prior knowledge, on the other hand, if you do not have prior knowledge of Linear Algebra and you love the visual stuff, this course is totally for you.

And also this one is really good too.

Honestly, after viewing too many courses + reading books, and taking notes, I again want to explain to you guys briefly, so in approximately 6–7 minutes, you will figure out much of these terms.

If you are newly reading my article, I also have many A-Z articles about Statistic- Regression, Classification, and Machine Learning terms.

Here are examples;

I am writing these articles because I struggled while learning Machine Learning and I can not reach the right sources by writing that article, I am refreshing my knowledge about Linear Algebra.

Repetition is the mother of learning, the father of action, which makes it the architect of accomplishment.” Zig Ziglar

After many years, I have now discovered the things you should learn to master in Machine Learning.

You can read my previous articles but briefly, you should be good in the following terms

  • Linear Algebra
  • Calculus
  • Statistics and Probability
  • Programming – my choice is Python
  • General Logic of Machine Learning

And after knowing these things, it is good to test your skills in real-life data sets.

You can find good data sets and also brief courses on Kaggle.

Now let’s dive into the terms.

Operations are made in the same linear space.

1 Dimensional Vector

Vector, which has only 1 dimension.

Shape: (x, )

Image by Author

2 Dimensional Vector

Vector, which only has 2 dimensions.

Shape: (x,y)

Image by Author

3 Dimensional Vector

Vector, which has 3 Dimensions.

Shape : (x,y,z)

Image by Author

Scaling

Multiplying vector with a number.

Scaling Formula

Image by Author

Scaling Python Implementation

Image by Author

Scaler

Now, z is a scaler.

L1 Norm

The length of a vector.

(Manhattan Norm)

Image by Author

0.2,0.3,0.5 = 1

Image by Author

L2 Norm

(Euclidean Norm)

The euclidian calculation of a vector.

L2 Norm Formula

Image by Author

5,12 = 13 (square root(5’’2 + 12’’2 ))

L2 Norm Python Implementation

Image by Author

Vector Multiplication

  • If the length of both vectors is equal then we can do multiplication.

Vector Multiplication Formula

  • We simply multiply the corresponding elements of both vectors and then create a new vector.

Image by Author

Vector Multiplication Python Implementation

Image by Author

Vector Dot Operation

  • Dot operations name come from the symbol we used to show this process.

Image by Author

Vector Dot Formula

  • When calculating the dot product of a vector, we simply chose every element of both vectors and then calculate the sum.

Image by Author

Let us see the Python implementation of these actions.

Vector Dot Python Implementation

Image by Author

Vector Matrix Multipication

Again dot method.

Vector Matrix Multiplication Formula

Vector Matrix Python Implementation

Image by Author

Matrix Scalar Multiplication

Now, let us multiply the vector with a scalar.

Matrix Scalar Multiplication Formula

Image by Author

Matrix Scalar Multiplication Python Implementation

Image by Author

Matrix Matrix Multiplication

When we’ll do Matrix-matrix multiplication, we will use the dot method.

Matrix-Matrix Multiplication Formula

Image by Author

Matrix-Matrix Multiplication Python Implementation

Image by Author

Matrix Transpose

We will use .T method.

Matrix Transpose Formula

Image by Author

Matrix Transpose Python Implementation

Image by Author

Matrix Inverse

When the multiplication of two matrices results in the Identity matrix, one matrix will be another inverse.

Matrix Inverse Formula

Image by Author

Matrix Inverse Python Implementation

Image by Author

Matrix Determinant

We will use .det method to calculate a result.

The result of the determinant of the matrix tells you if the matrix is invertible or not.

When the end result is zero, which means the matrix has no inverse.

Matrix Determinant Python Implementation

Image by Author

Square Matrix

Row number = column number

Square Matrix Python Implementation

Image by Author

Identity Matrix

All values from top left to right bottom, in the main diagonal are 1.

Identity Matrix Python Implementation

Image by Author

Orthogonal Matrix

If the result of the dot products of two vectors is zero, these two vectors are orthogonal.

Orthogonal Matrix Formula

Image by Author

Diagonal Matrix

When the values except the main diagonal are zero, that will be a diagonal Matrix.

Diagonal Matrix Formula

Image by Author

Diagonal Matrix Python Implementation

Image by Author

Now let’s look up dimension transformations.

One dimension to two dimensions and two to three.

Not if you read here it is important to remind that the .shape method returns a tuple (x,y).

  • x = Number of Rows
  • y = Number of Columns

1D to 2D

Now here, a one-dimensional array is created, as we can see the shape.

After that, we can use reshape method to create a 2d dimension.

1D to 2D Python Implementation

Image by Author

2D to 3D

First, we define a 2D dimension array that transforms it into 3 as we use the first 2 dimensions according to our 2D dimension.

2D to 3D Python Implementation

Image by Author

Of course, there are many terms that can be related to Linear Algebra, however knowing these terms can give you a quick insight into Linear Algebra.

Now you are familiar with Linear Algebra, you can develop your skills by reading books or watching courses.

All codes used in these article are here;

If you want to see other articles like this one and machine learning applications like Face Recognition & Loan Application Analysis, please subscribe to me;

See you next time.

“Machine learning is the last invention that humanity will ever need to make.” Nick Bostrom

Source: https://medium.datadriveninvestor.com/linear-algebra-a-z-for-machine-learning-68dadcd0b757

npressfetimg-1204.png
Machine learning

Machine learning models development for shear strength prediction of reinforced concrete beam: a comparative study … – Nature.com

Siddika, A., Al Mamun, M. A., Alyousef, R. & Amran, Y. H. M. Strengthening of reinforced concrete beams by using fiber-reinforced polymer composites: A review. J. Build. Eng. 25, 100798 (2019).

Google Scholar 

<p class="c-article-references__text" …….

Read More
npressfetimg-1131.png
Machine learning

Organic reaction mechanism classification using machine learning – Nature.com

Simonetti, M., Cannas, D. M., Just-Baringo, X., Vitorica-Yrezabal, I. J. & Larrosa, I. Cyclometallated ruthenium catalyst enables late-stage directed arylation of pharmaceuticals. Nat. Chem. 10, 724–731 (2018).

Article 
CAS 

Google Scholar 
…….

Read More
npressfetimg-1058.png
Machine learning

Generative AI: how will the new era of machine learning affect you? – Financial Times

Copyright The Financial Times Limited 2023. All rights reserved.

Follow the topics in this article

Markets data delayed by at least 15 minutes. © THE FINANCIAL TIMES LTD 2023. FT and ‘Financial Times’ are trademarks of The Financial Times Ltd.The Financial Times and its journalism are subject to a self-regulation regime under the FT Editoria…….

Read More