"sequentialfs'' selects only the first column in the feature set.
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Aditya
2025년 7월 22일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!