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

相关推荐
且撷相思红豆枝18 小时前
Simulink学习笔记(一)
笔记·学习·matlab
星夜离尘5620 小时前
MATLAB 角度解缠遇到丢样:先分段,再说明圈数为什么不可恢复
开发语言·matlab
数据皮皮侠20 小时前
全国休闲农业与乡村旅游示范县政策DID(2010-2025)
大数据·人工智能·搜索引擎·数据挖掘·智慧城市·制造
MindUp20 小时前
AI 能帮我做数据分析吗?从使用场景看三类辅助方式
人工智能·数据挖掘·数据分析
听风吹等浪起21 小时前
第25章:基于ConvNeXt实现肺部CT肺癌四分类:数据集、训练调优、网络结构与Streamlit网页部署
人工智能·分类·数据挖掘
总要学点什么2 天前
第79篇:数据可视化-模拟迁徙效果——把三十条航线画成会飞的弧
3d·信息可视化·数据挖掘·数据分析·gis·webgl·cesium
Apok'2 天前
零基础学Python量化(1):研究大纲与流程
python·机器学习·金融·数据挖掘·数据分析
STLearner2 天前
KDD 2026 | (2月轮)时空数据(Spatial-Temporal)论文总结时空【下】(人群移动,城市科学(资源调度,)
大数据·人工智能·python·深度学习·机器学习·语言模型·数据挖掘
chhttty2 天前
Simulink电机控制框架
matlab·simulink
机器学习之心2 天前
电池SOH估计和RUL预测,五个时间特征 + 基于GPR高斯过程回归的锂电池健康状态估计和剩余寿命预测
人工智能·数据挖掘·回归·锂电池健康状态估计·剩余寿命预测