Newral Networks-task
Newral Networks-task
Objective:
The student is tasked with creating a MATLAB-based neural network to classify simple data into two
classes. The data will consist of two randomly generated sets of points on a 2D plane. The project
aims to demonstrate how a neural network functions and can be applied for classification tasks.
Task Description:
1. Generate Data:
o Split the data into a training set (70%) and a testing set (30%).
o Visualize the decision boundary of the neural network (using meshgrid for
visualization).
5. Conclusion:
Expected Deliverables:
Submit a MATLAB script containing the complete code, results (plots, test results), and a short report
in PDF format.
Guide for Students
Neural networks are models inspired by the human brain's functioning. They are widely used for
tasks like classification, regression, and image recognition. The core building block of a neural
network is the neuron, which performs mathematical operations on inputs to produce an output.
% Set parameters
rng(0); % Fixed seed for reproducibility
numPoints = 50;
% Class 1
x1 = -2 + randn(numPoints, 2);
y1 = zeros(numPoints, 1); % Label: 0
% Class 2
x2 = 2 + randn(numPoints, 2);
y2 = ones(numPoints, 1); % Label: 1
% Combine data
inputs = [x1; x2]';
targets = [y1; y2]';
% Split into training and testing sets
trainRatio = 0.7;
testRatio = 0.3;
% Display results
confMat = confusionmat(testTargets, testPredictions);
disp('Confusion Matrix:');
disp(confMat);
% Decision boundary
[xGrid, yGrid] = meshgrid(-5:0.1:5, -5:0.1:5);
gridPoints = [xGrid(:), yGrid(:)]';
gridOutputs = net(gridPoints);
gridPredictions = reshape(gridOutputs, size(xGrid));
% Plot
figure;
hold on;
scatter(x1(:,1), x1(:,2), 'b', 'filled');
scatter(x2(:,1), x2(:,2), 'r', 'filled');
contour(xGrid, yGrid, gridPredictions, [0.5 0.5], 'k',
'LineWidth', 2);
title('Neural Network Decision Boundary');
legend('Class 1', 'Class 2', 'Decision Boundary');
hold off;
Summary:
This example demonstrates step-by-step how to build a simple neural network in MATLAB for data
classification. The project provides hands-on experience and an understanding of the fundamentals
of neural networks.