Programming A Driverless Car Chapter 2: Linear Algebra for Machine Learning
Linear Algebra for Machine learning with Python
Python has certain libraries like scipy, numpy and many more they help us to know us the kernel methods of machine learning. Linear Algebra is a mathematical method which contains vector spaces and linear mapping between those spaces. It is study of lines, sub spaces. It is more of a representation of linear data conforming to certain notions and practices. Machine learning algorithms are not efficient enough specially to deal with large data therefore we need linear algebra to deal with it. As we know, representation of large form of data in the form of matrices helps us better visualise the data.
One more advantage of matrices is that all the calculation and processes performed on the data is in the form of matrices or batches ie. we have thousand of data examples which we don’t represent individually. Matrices has all form of data represented in the form of single entity. That is why Linear algebra is very important in machine learning and robotics. For ex. we have seen so many 3-D and animation movies. We have seen so many characters walk on screen and all this has been made possible only with the help of linear algebra.
Linear algebra is best represented in the form of linear equations.We will learn here how to use linear algebra for machine learning using Python. We will discuss these topics:
- Defining arrays and matrices
- Working with matrices
- Solving Equations
Define your arrays, inverse or transpose.
Defining Arrays and Matrices:
We will talk about linear algebra using Python using numpy library. Contents:
- Defining array and matrices
- Transpose, inverse and basic operations
- Eigen values & Eigen Vectors
- Solving Equations
- First, how to install a particular library or module in python. For ex. Numpy.
Go to command prompt and write
Pip install numpy
This will install numpy online. Once it is installed check it by writing
>>> import numpy
(if no error, that means it has been installed)We can also import a package as some other name. Like
Install numpy as np
- So, whenever you need to refer numpy, we will use np.
>>>import numpy as np
>>>from numpy.linalg import eigNow, we will define arrays and matrices using python and linear algebra.
>>>import numpy as np1
Working with matrices
MATLAB Style of defining Matrix
#To find transpose of a matrix
>>>C=B.T -----Storing it in C
#to find inverse
>>>from numpy.linalg import inv
matrix ([[0.833333333, -0.1666666666], [-0.6666666667,0.333333331])
#for dot operator that does row by column multiplication
>>> matrix([[32,42],[56,73]]) -------- This will do column by row
>>> A*B -------- will also work
Indexing of Matrix
array([[ 1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
For solving particular equations–
>>> from numpy.linalg import solve
array ([[4, 5], [6, -3]])
Eigen values & Eigen Vectors
The eig returns two tuples: the first one is the eigenvalues and the second one is a matrix whose columns are the two eigenvectors.
Recommended Reading: Chapter 1 Getting Started with Python
Next: Chapter 3 Introduction to Artificial Intelligence
To start reading from a topic of your choice, you can go back to the Table of Contents here
This course evolves with your active feedback. Do let us know your feedback in the comments section below.
Looking for jobs in Artificial Intelligence? Check here