"sequentialfs'' selects only the first column in the feature set.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am employing sequential feature selection to select the best feature set for classification. I used matlab routine "sequentialfs", as attached here. I am facing the problem that function only return the first column of the feature sets, whatever the feature set you feed.

I do appreciate your help in advance.
if true
% code
end
clc
close all
clear all
RF=load('FeaturesforSeq.mat');
Target=load('LabelforSeq.mat
%x is 3826x32
%y is 3826X1
RF=struct2cell(RF);
x=cell2mat(RF);
Label=struct2cell(Target);
y=cell2mat(Label);
xtrain = x(1:2500,:); xtest = x(2501:end, :);
ytrain = y(1:2500); ytest = y(2501:end);
c= cvpartition(y,'k',2);
opts = statset('display','iter');
fun = @( xtrain, ytrain, xtest, ytest)...
(sum(~strcmp(ytest,classify(xtest,xtrain,ytrain,'quadratic'))));
[fs,history] = sequentialfs(fun,x,y,'cv',c,'options',opts);
Feature_select = find(fs==1);
0 Kommentare
Antworten (1)
Aditya
am 22 Jul. 2025
Hi Ounkhin,
The issue you’re experiencing with sequentialfs always selecting the first feature is commonly due to either the data format, label types, or the function handle used for evaluation. First, make sure your feature matrix x contains meaningful, non-constant data across all columns, and your label vector y is appropriately formatted (either as numeric or a cell array of strings). If your labels are numeric, using strcmp in your function handle will not work as intended and may cause the feature selection to behave incorrectly. Instead, compare labels with ~= for numeric labels. It’s also recommended to use MATLAB’s newer classification functions like fitcdiscr rather than the older classify function for better compatibility.
Below is a revised approach with key debugging steps and a corrected function handle:
clc; close all; clear all;
RF = load('FeaturesforSeq.mat');
Target = load('LabelforSeq.mat');
x = struct2cell(RF); x = cell2mat(x);
y = struct2cell(Target); y = cell2mat(y);
% Debugging: Check data integrity
disp('Size of x:'); disp(size(x));
disp('Unique labels in y:'); disp(unique(y));
disp('Standard deviation of features:'); disp(std(x));
% Cross-validation partition
c = cvpartition(y, 'k', 5);
opts = statset('display', 'iter');
% Use fitcdiscr for classification and numeric comparison for labels
fun = @(xtrain, ytrain, xtest, ytest) ...
sum(ytest ~= predict(fitcdiscr(xtrain, ytrain, 'DiscrimType', 'quadratic'), xtest));
[fs, history] = sequentialfs(fun, x, y, 'cv', c, 'options', opts);
Feature_select = find(fs);
disp('Selected feature indices:');
disp(Feature_select);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Regression 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!