You are on page 1of 20

Machine learning

Types of ML
• Supervised learning
– Classification
– Regression
• Unsupervised learning
– Clustering
– Association
• Reinforcement learning
– Markov Decision Process
– Q learning
• Simi-supervised
– transductive learning
– inductive learning
Traditional ML algorithms
• Supervised
– Logistic Regression (fitglm(), glmfit(),glmval())
– SVM (fitcsvm(),fitcecoc())
– Decision Tree Classifier(binary, fitctree())
– K-Nearest Neighbor Classifier (classificationKNN(), ficknn())
– Random Forest Classifier(regresion, fitrensemble())
• Unsupervised
– K-means clustering (kmeans(x,k))
– Hierarchal clustering (clusterdata(x,cutoff))
– Principle Component Analysis (pca(x))
– Singular value decomposition (svd(x))
Advanced ML algorithms
• Neural Networks
– Feed forward NN: (feedforwardnet(size))
– Pattern recognition: (patternnet(size))
– RNN: layrecnet(layerDelays,Sizes,trainFcn)
– DNN: resnetLayers(), deepNetworkDesigner()
Load IRIS dataset and design Model
• Read csv data from disk
– fishertable = readtable(‘fisheriris.csv’);
• Split your dataset into features/input and
target(output)
– Input = fishertable(:,1:4);
– Target=fishertable(:,5);
View/Modify model arch
• View training functions
– Model.trainFcn
• Change the function
– Model.trainFcn = ‘#name’
View/Modify model arch
• View activation function
– Model.layers{#num}.transferFcn
• Change the function
– Model.layers{#num}.transferFcn = ‘#name’
Name Function output description
tansig corresponding tan value of input
logsig corresponding log value of input
purelin calculates the differential value of input

softmax maximum and minimum fall between (1,0)


View/Modify model arch
• View dataset division function
– Model.divideFcn
• Change the function
– Model.divideFcn = ‘#name’

Name Function output description


dividerand Random rows chosen for all
divideind Index of rows used for selecting dataset
divideint Interleaved rows chosen for all
divideblock First block for train, second for validation,…
View/Modify model arch
• View dataset division ratio
– Model.divideParam
• Change the function
– Model.divideParam.trainRatio = value1
– Model.divideParam.valRatio = value2
– Model.divideParam.testRatio = val3
Train Models
• KNN
– Model1 = fitcknn(input,output);
• Neural network
– Model2 = fitnet(10);
– Model2=train(Model2,input’,output’);
• Decision tree
– Model3 = fitctree(input,output);
Machine learning

For Image recognition


Capturing Images
• Create an object to handle your camera
– Android: phone = mobiledev()
– Windows: source = webcam(#)
• Create the camera
– Mycamera1 =camera(phone,’front’)
– Mycamera2 = camera(phone,’back’)
• Capture image snapshots
– Image1 = mycamera.capture(#method)
– Method=‘immediate’ or ‘manual’
Reading images from folder
• Reading single image
– Image2 = imread(‘directory’)
• If using matlab online, need to install matlab
drive
• Read multiple images in a dir
– imagefiles = dir('*.jpg');
– nfiles = length(imagefiles);
• Use loop to read all images into array
Reading images from folder…
List = dir(‘path', '**', '*.ext');
Array = [];
for k = 1:numel(List)
img = imread(fullfile(List(k).folder,
List(k).name));
if isempty(Array)
Array = zeros([size(img),
numel(List)]);
end
Array(:, :, :, k) = img;
end
Reading entire folder/subfolder
• Read images based on sub directory name
– allImages=imageDatastore(‘#foldern
ame','IncludeSubfolders',true,
'LabelSource','foldernames','FileE
xtensions',‘#ext');
Displaying image
• Single image:
– Imshow(image1)
• Compare images
– Imshowpair(image1,grayImage1)
Need to reduce dataset
• RGB images are represented using 3-D array
• If single image has 1000x1000 dimension
– Need to use 1000x1000X3 = 3,000,000 numbers
• If we have 1000 such images
– Need to have 3,000,000,000 numbers
• PCs can’t afford this number for manipulation
• Need to reduce image
– Cropping. Resizing. Converting to Gray and BW
Cropping and Resizing
• Cropping image
– croppedIm1 = imcrop(image1, #shape);
– croppedIm1 = imcrop(image1,[50,50])
• Resize to 64x48
– resizedIm1=imresize(image1,[64,48])
• Resize to 50% of original image?
Converting to grayscale
• Convert image to gray
– grayIm1 = im2gray(image1);
Binarize image (black and white)
• Find gray level threshold
– Level = graythresh(grayImage)
• Use the level to get black and white image
– blckWt=imbinarize(grayImage, level);
• Compare images
– imshowpair(grayIm,blckWt,'montage');

You might also like