Data Classification using multi-class SVM in MATLAB

Data classification

Data classification simply means categorizing structured or unstructured data based on type, content and other features. Data classification has improved significantly over time. Today, this technology is used for a variety of purposes, often in support of data security initiatives. But data may be classified for a number of reasons, including ease of access, maintaining regulatory compliance, and to meet various other business or personal objectives. MATLAB is an efficient tool for data classification. Supervised and semi-supervised learning algorithms can be used for binary and multiclass problems.



What is a Support Vector machine?

Support Vector Machine (SVM) is a machine learning algorithm that analyses the data for classification and regression analysis. An SVM maps training data to points in space so as to maximize the width of the gap between the two categories. Then test data are mapped into that same space and predicted to which category they belong based on which side of the gap they fall.

A basic code for classification using multiSVM is below

clc;
clear;
close all;
% load data (we used in-built ionosphere data here)
load ionosphere    
data=X';    %features
label=categorical(Y);    %labels
%% now partition data into training and testing set
n = length(label);
h = cvpartition(n,'Holdout',0.2);    %  partition
idxTrain = training(h);
dataTrain = data(:,idxTrain);    %train data
labelTrain=label(idxTrain);    % train label
idxNew = test(h);
datatest = data(:,idxNew);    %  test data
labelTest=label(idxNew);     % test label
%% train the classifier with training data
% here I have used SVM (multi class SVM classifier)
model=fitcecoc(dataTrain',labelTrain);     % create model with train data and label
%% predict the classifier output for test data
ypred=predict(model,datatest');    % predict the output using trained model
%% performance evaluation
AccuracySvm=(sum(ypred==labelTest))/length(labelTest);    % calculate accuracy of prediction
fprintf('Accuracy of SVM classifier = %d\n',AccuracySvm)









Comments

Popular Posts