 clc; close all;
 clear all;
 
 % Data File for marks of students in two subject 
 % to determine whether a student is pass or fail
 
 marks=xlsread('marks.xlsx');
 y_train=marks(:,end); % Target variable
 x_train=zscore(marks(:,1:end-1));% Normalized Predictors
 
 p=length(marks);

 x_train=[ones(length(x_train),1) x_train]; % one is added for calculation of biases.
 x_test=x_train;
 y_test=y_train;
 
 %compute cost and gradient
 iterations=100; % No. of iterations for weight updation
 
 thetas=zeros(size(x_train,2),1); % Initial weights
 
 alpha=0.1 % Learning parameter
 
 [J grad h new_thetas]=cost(thetas,x_train,y_train,alpha,iterations) % Cost funtion
 
 y_pred=x_test*new_thetas; %target prediction
 
 % probability calculation
 [hypo]=logsig(y_pred); % Hypothesis Function
 y_pred(hypo>=0.5)=1;
 y_pred(hypo<0.5)=0;

 % Decision Boundary
 syms x1 x2 % Short-cut for constructing symbolic variables.
 fnn=new_thetas(1)*1+new_thetas(2)*x1+new_thetas(3)*x2-0.5

 figure
 hold on
 scatter(x_test(y_test==1,2),x_test(y_test==1,3),'b+','linewidth',2.0)
 scatter(x_test(y_test==0,2),x_test(y_test==0,3),'r','linewidth',2.0)
 h1=ezplot(fnn)
 set(h1,'color','r')
 legend('+ class','- class','Decision boundary')
