0% found this document useful (0 votes)
36 views7 pages

Modelling of Ic Classifier Using Logistic Regression: %initialization

This document describes modeling an IC classifier using logistic regression in MATLAB. Key steps include: 1. Loading training data to classify ICs as normal or abnormal based on power profiles and assigning labels. 2. Computing the hypothesis, cost function, and gradient to determine optimal theta values that minimize cost. 3. Using the theta values to calculate the decision boundary and plot the sigmoid function. 4. Loading test data, making predictions, and computing performance metrics like accuracy, precision, and recall by generating a confusion matrix. The classifier achieves 98% accuracy on the test data.

Uploaded by

Javeria Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Modelling of Ic Classifier Using Logistic Regression: %initialization

This document describes modeling an IC classifier using logistic regression in MATLAB. Key steps include: 1. Loading training data to classify ICs as normal or abnormal based on power profiles and assigning labels. 2. Computing the hypothesis, cost function, and gradient to determine optimal theta values that minimize cost. 3. Using the theta values to calculate the decision boundary and plot the sigmoid function. 4. Loading test data, making predictions, and computing performance metrics like accuracy, precision, and recall by generating a confusion matrix. The classifier achieves 98% accuracy on the test data.

Uploaded by

Javeria Farooq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

MODELLING OF IC CLASSIFIER USING LOGISTIC REGRESSION

Introduction

1. The desired goal for modelling a logistic regression classifier is to critically


evaluate ICs for abnormal behavior and reject suspicious ICs given the power profile
of un-intruded and intruded chips. To bifurcate between normal and abnormal chips,
a classifier has been built on MATLAB. The complete code for classifier is given in
this document.

MATLAB code for IC Classifier

(a). Under mentioned code has been written in MATLAB for bifurcation of ICs :-

----------------------------------------------------------------------------------------------------------------
%Initialization

clear; close all; clc

%Loading Training Data and allocating ones for acceptable ICs and zeros for
unacceptable ICs

filename='datatr.xlsx'
Range1= 'A2:A27';
Range2= 'B2:B27';
X1 = xlsread(filename,Range1);
X2 = xlsread (filename,Range2);
X = repelem (X1,X2);
Y=[ones(500,1); zeros(500,1)];
figure('name','Logistic Regression Training Data Plot')
scatter(X,Y,60,'m', 'filled');
xlabel('Power (watts)')
ylabel('Bifurcation of ICs')
hold on;

%Finding Hypothesis, Cost and Gradient


[m, n] = size(X);
int_theta = zeros(n + 1, 1);
[costJ,grad]=compute(int_theta,X,Y);

%Finding Optimal Theta and Optimal Cost for Training Data


[theta, cost] =fminunc(@(t)(compute(t, X, Y)), int_theta);

%Calculating Decision Boundry


theta1=theta(1,:)
theta2=theta(2,:)
d=-theta1./theta2;
%Plotting Decision Boundary
plot([d d],[0 1])
legend('Training Set', 'Decision Boundary')

%Plotting Sigmoid
fplot(@(X) (1 ./ (1 + exp(-(theta1+theta2*X)))), [0.3 0.4], 'b');
legend('Training Set', 'Decision Boundary', 'Sigmoid')

% Loading Test Data to determine accuracy of Classifier


filename2='testdata.xlsx';
Range3= 'A2:A30';
Range4= 'B2:B30';
Z1 = xlsread(filename2,Range3);
Z2 = xlsread (filename2, Range4);
Z = repelem (Z1,Z2);
Actual=[ones(100,1); zeros(100,1)];
scatter(Z,Actual,80,'r'); % plotting test data
legend('Training Set', 'Decision Boundary', 'Sigmoid', 'Test Set')
hold off;

%Predicting Values for each tuple of Test data

for k= 1:size (Z),


Predict(k) = sigmoid([1 Z(k)] * theta);
end

% Assigning value <0.5==0 and value>=0.5 == 1

Predicted=round(Predict');

%Finding Confusion Matrix

C= confusionmat (Actual, Predicted)

TP=C(1,1);, FN=C(1,2);, FP=C(2,1);TN=C(2,2);

%Measuring Performance Parameters of developed Classifier

Accuracy= ((TP+TN)./200)*100;
Precision= (TP./(TP+FP));
Recall= (TP./(TP+FN));
Fscore= 2*((Precision*Recall)./(Precision+Recall));

fprintf('Accuracy of Classifier: %f\n', Accuracy);


fprintf('Precision: %f\n', Precision);
fprintf('Recall: %f\n', Recall);
fprintf('Fscore: %f\n', Fscore);
------------------------------------------------------------------------------------------------------
Functions Used in MATLAB Code

1. Compute (theta, X, Y)

2. Sigmoid Function

--------------------------------------------------------------------------------------------------------------

Determination of Decision Boundary

(b) The developed classifier is performing logistic regression algorithm based on


one feature (power). After calculation of optimal theta, values of theta1 and theta2
have been used to determine the decision boundary

theta1+theta2x>=0
theta2x=-theta1
X = -theta1/theta2

x= decision boundary which is denoted by ‘d’ in MATLAB code and value of


decision boundary as determined by MATLAB is 0.3407

MATLAB code for calculation and plotting of decision boundary is appended below
MATLAB Code for Decision Boundary

MATLAB Plot for Decision Boundary


Cost Computation and Most Important Parameters (theta) for Model

(c) Under mentioned cost function forlogistic regression has been


calculated in MATLAB code and is denoted by costJ

Cost function and important parameters (thetas) have been calculated using
following MATLAB

Cost Function comes out to be 0.6931. The values for cost function and thetas have
been optimized by using undermentioned code

The optimal values of cost and theta are as following:

Cost= 0.0314

theta1 = 630.5520

theta2 = -1.8506e+03
Plot of Sigmoid Function

Sigmoid Function has been plotted using values of calculated theta1 and theta2 and
same is appended below:-

Confusion Matrix

(d) After calculation of hypothesis, cost and thetas, Test data was predicted using
the developed classifier. The predicted values and actual power values of test data
were then compared to plot confusion matrix

The MATLAB code for matrix is as under:


The confusion Matrix comes out as

C= 97 3
2 98

TP= 98, FN= 3, FP= 2, TN=98

You might also like