SVM classification using LIBSVM, Accuracy Problem
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have datasets belongs to two different classes as given in attached xls file. I converted the data into "train data" set and "test data" set in CSV format
I have still doubt on the way i am giving input to the program.
If i run my attached matlab code, it is always showing 50% accuracy only...
Please let me know whether i am giving input data correctly or not, and how to get good accuracy?
here the test data is a part of train data only...
0 Kommentare
Antworten (1)
Aditya
am 22 Jul. 2025
Hi HST,
When working with neural networks for classification in MATLAB, it’s crucial to properly format your input data and target labels. For a two-class classification problem, your feature matrix should have samples as columns and features as rows. The target labels should be converted to a one-hot encoded format, where each class is represented by a vector (for example, class 1 as [1; 0] and class 2 as [0; 1]). If you use raw class labels (like 1 and 2) instead of one-hot vectors, the network will not be able to learn the classification task correctly, which often leads to an accuracy of around 50%—equivalent to random guessing.
Below is an example of how you should prepare your data and train a simple neural network in MATLAB:
% Load your CSV data
trainData = readmatrix('train.csv');
testData = readmatrix('test.csv');
% Separate features and labels
X_train = trainData(:, 1:end-1)'; % Features as rows, samples as columns
y_train = trainData(:, end); % Class labels (1 or 2)
X_test = testData(:, 1:end-1)';
y_test = testData(:, end);
% Convert labels to one-hot encoding
T_train = full(ind2vec(y_train')); % Now T_train is 2 x N
T_test = full(ind2vec(y_test'));
% Create and train the neural network
net = patternnet(10);
net = train(net, X_train, T_train);
% Predict on test data
Y_pred = net(X_test);
% Convert network output to class labels
[~, predicted_labels] = max(Y_pred, [], 1);
% Calculate accuracy
accuracy = sum(predicted_labels' == y_test) / numel(y_test);
fprintf('Test Accuracy: %.2f%%\n', accuracy*100);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!