Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sns College of Technology: Department of Civil Engineering

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

SNS COLLEGE OF TECHNOLOGY

AN AUTONOMOUS INSTITUTION
Approved by AICTE New Delhi & Affiliated to Anna University Chennai
Accredited by NBA & Accredited by NAAC with “A+” Grade, Recognized by UGC
COIMBATORE

DEPARTMENT OF CIVIL ENGINEERING

MACHINE LEARNING FOR CIVIL ENGINEERS

II YEAR / IV SEMESTER

Unit 5 : Softwares in Machine Learning


Topic 1 : Machine Learning in MATLAB

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSCT 1/10


Objective

• Get the size of an object with ’size’. Takes an optional argument


to specify the dimension (without, it returns an array with the
sizes of all dimensions). Example:
A = [1 2 3
4 5 6]
size(A,1) = 2
size(A,2) = 3
size(A) = [2 3]

• Use ’...’ to let commands span several lines.


• Clear memory by deleting some unused variables using ’clear
variable-name’
• ’who’ and ’whos’ show the variables in the workspace.
• Use ’drawnow’ to draw now (flush the event queue) ...
2
• Use ’save’ to save the current workspace. ’load’ to get it back.

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 2/10


) Use ’repmat’ to build new matrices from smaller ones.
Example:
x = [1;2]
repmat(x,1,3) = [1 11
2 2 2]
repmat(x,2,2) = [1 1
2 2
1 1
2 2]

) Used mostly to ’vectorize’ things (more in a


moment...)

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 3/10


Representing Data

) We are often dealing with lots of data, and normally that data is given in the
form of real-vectors. If not, we can often massage it accordingly... (performing
feature extraction).
) It is convenient to use matrices to store data, for example by stacking the
vectors column-wise:

X = (x1x2 . . . xN )

) To display up to 3-d data given in this form, you could use


scatter(X(1,:),X(2,:)) % display 2-d dataset
scatter3(X(1,:),X(2,:),X(3,:)) % display 3-d dataset

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 4/10


High Dimensions

) We can index arrays linearly (regardless of the number of dimensions).


Example: If A=[1 2;3 4], then A(3) = 3.
) Summarizing operations, such as ’sum’, ’mean’, etc. can be applied to arrays of
any dimension (not just vectors). Use an additional argument to specify over
which dimension to perform the operation. Example: If A = [1 2 ;3 4], then
sum(A,1) = [4 6]
sum(A,2) = [3
7]

) Many operations on vectors and matrices extend to objects with more than 1 or
2 dimensions. Example: Construct a random 5 × 5 × 5-array with
’randn(5,5,5)’.

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 5/10


Vectorizing
) Applying the linear function to data-points stacked column-wise in a matrix X is
simply Y = wT X .
In MATLAB:
Y = w’*X;
) In MATLAB writing stuff in matrix form can be faster than using loops. Referred to as
’vectorization’.
) Another example. Suppose you want to mean center a set of vectors stored in X . Instead
of
m = mean(X,2);
for i = 1 : size(X,2) X ( : , i i ) = X ( : , i i ) - m;
end

we could write:
X = X - repmat(mean(X,2),1,size(X,2));

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 6/10


Linear Classification

Classification: We are given some data with associated class-labels,


and want to learn the underlying function, that maps inputs to
labels.
) Examples: Spam filtering, face recognition, intrusion detection,
... and many many many more.
) For now we consider only binary problems (2 classes). Most ideas
can be quite easily extended to more than 2.
) Again, we will use a linear model. In particular:
f (x) = sgn(wT x)
) This means that we try to separate classes using a hyper-plane.

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 7/10


) Again we can use MATLAB to visualize what’s going on:
X = [randn(3,200)-ones(3,200)*1.8 . . .
randn(3,200)+ones(3,200)*1.8]; %produce some inputs Y =
[zeros(1,200), ones(1,200)]; %produce some labels
scatter3(X(1,:),X(2,:),X(3,:), 80, Y, ’ f i l l e d ’ ) ;

) How well does some random w do on the training set?


w = randn(3,1); Y_random = sign(w’*X);
scatter3(X(1,:),X(2,:),X(3,:),80,Y_random, ’ f i l l e d ’ ) ; hold
on;
plot3([0 w(1)], [0 w(2)], [0 w(3)], ’ k ’ ) ; %show w hold off;
sum(Y_random~=Y)/200 %error rate

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 8/10


Conclusion

) A lot of machine learning is based on the simple ’neuron’:


wT x
) We have looked at basic regression and classification.
) Usually a few lines in MATLAB.
) A couple of things were oversimplified here. For example, in
practice we would adapt the learning rate in gradient descent,
add an extra input-dimension for the bias, etc.
) Can be easily applied to real data: E.g. Spam, ...

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 9/10


Thank You!!

11/16/2023 Machine Learning in MATLAB/ MLCE/ /Sathya S / AP / CIVIL/ SNSC 10/10

You might also like