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

相关推荐
lingchen19064 小时前
MATLAB图形绘制基础(一)二维图形
开发语言·算法·matlab
qq_436962186 小时前
奥威BI:AI数据分析赋能企业智能决策
人工智能·数据挖掘·数据分析
兮兮能吃能睡9 小时前
数据分析核心术语略解
数据挖掘·数据分析
Evand J10 小时前
【MATLAB例程】二维环境定位,GDOP和CRLB的计算,锚点数=4的情况(附代码下载链接)
开发语言·matlab·定位·toa·crlb·gdop
沐欣工作室_lvyiyi11 小时前
用于电动汽车的永磁同步电机调速系统建模与仿真(论文+)
matlab·仿真·永磁同步电机·无传感器
机器学习之心11 小时前
MATLAB基于灰靶决策模型的高校信息化设备供应商选择研究
matlab·灰靶决策模型
Chef_Chen12 小时前
数据科学每日总结--Day4--数据挖掘
人工智能·数据挖掘
渡我白衣13 小时前
AI 应用层革命(一)——软件的终结与智能体的崛起
人工智能·opencv·机器学习·语言模型·数据挖掘·人机交互·集成学习
刘孬孬沉迷学习13 小时前
AI+通信+多模态应用分类与核心内容总结
人工智能·机器学习·分类·数据挖掘·信息与通信
周杰伦_Jay14 小时前
【Mac下通过Brew安装Ollama 】部署 DeepSeek 轻量模型(实测版)
人工智能·macos·数据挖掘·database·1024程序员节