Fisher_Score分数计算

Fisher_Score 计算

自己实现的代码

matlab 复制代码
function W = fsFisher(data)
	%Fisher Score
	% Input:
	%	data: dataset 
	% Output:
	%   W: W(i) represents the Fisher Score of the i-th feature.  

	% numC = max(Y);
	Y = data(:, end); % 提取标签
	X  = data(:, 1:end-1); % 提取样本数据,去掉标签列
	unique_labels = unique(Y); % 获取所有唯一的类别标签
	numC = length(unique_labels); % 类别数量

	[~, numF] = size(X);
	W = zeros(1,numF);

	% statistic for classes
	cIDX = cell(numC,1);
	n_i = zeros(numC,1);
	for j = 1:numC
		%cIDX{j} = find(Y(:)==j);
		cIDX{j} = find(Y(:)==unique_labels(j));
		n_i(j) = length(cIDX{j});
	end

	% calculate score for each features
	for i = 1:numF
		temp1 = 0;
		temp2 = 0;
		f_i = X(:,i);
		u_i = mean(f_i);
		
		for j = 1:numC
			u_cj = mean(f_i(cIDX{j}));
			var_cj = var(f_i(cIDX{j}),1);
			temp1 = temp1 + n_i(j) * (u_cj-u_i)^2;
			temp2 = temp2 + n_i(j) * var_cj;
		end
		% check
		if temp1 == 0
			W(i) = 0;
		else
			if temp2 == 0
				W(i) = 100;
			else
				W(i) = temp1/temp2;
			end
		end
	end
end

matlab代码如下

matlab 复制代码
function [out] = fsFisher(X,Y)
%Fisher Score, use the N var formulation
%   X, the data, each raw is an instance
%   Y, the label in 1 2 3 ... format

numC = max(Y);
[~, numF] = size(X);
out.W = zeros(1,numF);

% statistic for classes
cIDX = cell(numC,1);
n_i = zeros(numC,1);
for j = 1:numC
    cIDX{j} = find(Y(:)==j);
    n_i(j) = length(cIDX{j});
end

% calculate score for each features
for i = 1:numF
    temp1 = 0;
    temp2 = 0;
    f_i = X(:,i);
    u_i = mean(f_i);
    
    for j = 1:numC
        u_cj = mean(f_i(cIDX{j}));
        var_cj = var(f_i(cIDX{j}),1);
        temp1 = temp1 + n_i(j) * (u_cj-u_i)^2;
        temp2 = temp2 + n_i(j) * var_cj;
    end
    
    if temp1 == 0
        out.W(i) = 0;
    else
        if temp2 == 0
            out.W(i) = 100;
        else
            out.W(i) = temp1/temp2;
        end
    end
end

[~, out.fList] = sort(out.W, 'descend');
out.prf = 1;

Bibtex 引用

@BOOK{Duda-etal01,
   title = {Pattern Classification},
   publisher = {John Wiley \& Sons, New York},
   year = {2001},
   author = {Duda, R.O. and Hart, P.E. and Stork, D.G.},
   edition = {2},
  }
}

来源:Feature Selection Package - Algorithms - Fisher Score

相关推荐
正在走向自律5 小时前
解锁Agent的数据分析潜能,开启智能决策新时代(19/30)
大数据·数据挖掘·数据分析
dundunmm5 小时前
【生物信息】h5py.File
python·机器学习·数据挖掘·h5py
HereLi6 小时前
低空经济——飞行汽车运营建模求解问题思路
运维·python·matlab
IT猿手7 小时前
部落竞争与成员合作算法(CTCM)求解5个无人机协同路径规划(可以自定义无人机数量及起始点),MATLAB代码
深度学习·算法·机器学习·matlab·无人机·无人机、
元周民10 小时前
matlab中高精度计算函数vpa与非厄米矩阵本征值的求解
matlab·矩阵
机智的小神仙儿10 小时前
基于ResNet的CIFAR-10分类实现与分析
图像处理·人工智能·数据挖掘
思通数科多模态大模型11 小时前
开源AI视频监控系统,助力公租房廉租房管理,打击倒卖行为
人工智能·深度学习·目标检测·机器学习·目标跟踪·自然语言处理·数据挖掘
deardao12 小时前
【顶刊TPAMI 2025】多头编码(MHE)之极限分类 Part 4:MHE表示能力
人工智能·深度学习·神经网络·分类·数据挖掘·极限标签分类·多头编码
goomind13 小时前
MATLAB深度学习实战文字识别
深度学习·计算机视觉·matlab·ocr·文字识别
CChuaizhi16 小时前
数学建模_基于支持回归向量机SVR的回归预测之预测新数据+Matlab代码包教会使用,直接替换数据即可
数学建模·matlab·回归