How to Import Inputs and Targets data for the classification task in Neural Network?
5 次查看(过去 30 天)
显示 更早的评论
Hello,
We have Software Defects dataset in ‘.CSV’ format. This file includes (334 x 37 Table) 344 Rows and 37 Columns. As a input, We are using 36 features and 37th is actually a class label, which included 0 and 1 values, 0 means no-defect, 1 means defective.
We want to import this dataset in to MATLAB by using Code, As you know for Neural network, we need Inputs and Targets, We want to give 36 attributes as inputs features, and 0 and 1 (mean non-defective and defective) as Targets. We need MATLAB code, how to import inputs and targets into MATLAB, and how we can create 0 and 1 Vectors as non-defective and defective? Because we want to use “2 neurons” in output layer of feed-forward neural network.
0 个评论
回答(1 个)
Akshat
2024-11-14,9:15
The issue of representing 0 and 1 in a feed-forward network with 2 output neurons can be resolved by representing 0 and 1 as vectors of size 2, that is, 0 -> [1,0] and 1-> [0,1].
As vectors of size 2 can take upto 4 output values, we can easily represent by saying the 0th output neuron will "light up" when the output is 0 (no defect) and 1st output neuron will light up when the output is 1 (defect).
Some boilerplate code you can use to perform this functionality:
filename = 'software_defects.csv';
data = readtable(filename);
inputs = data{:, 1:36}';
targets = data{:, 37};
% 0 -> [1; 0] (non-defective)
% 1 -> [0; 1] (defective)
numSamples = length(targets);
targetsNN = zeros(2, numSamples);
for i = 1:numSamples
if targets(i) == 0
targetsNN(:, i) = [1; 0];
else
targetsNN(:, i) = [0; 1];
end
end
net = feedforwardnet(10); % 10 hidden neurons, adjust as needed
net = configure(net, inputs, targetsNN);
net = train(net, inputs, targetsNN);
predictions = net(inputs);
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!