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

相关推荐
Matlab精灵2 小时前
Matlab函数中的隐马尔可夫模型
开发语言·matlab·统计学习
山海青风2 小时前
使用 OpenAI 进行数据探索性分析(EDA)
信息可视化·数据挖掘·数据分析
莫叫石榴姐3 小时前
数据科学与SQL:组距分组分析 | 区间分布问题
大数据·人工智能·sql·深度学习·算法·机器学习·数据挖掘
请你喝好果汁6417 小时前
单细胞|M3-4. 细胞聚类与轨迹推断
机器学习·数据挖掘·聚类
吾门8 小时前
YOLO入门教程(三)——训练自己YOLO11实例分割模型并预测【含教程源码+一键分类数据集 + 故障排查】
yolo·分类·数据挖掘
Matlab精灵9 小时前
Matlab科研绘图:自定义内置多款配色函数
算法·matlab
电子手信9 小时前
知识中台在多语言客户中的应用
大数据·人工智能·自然语言处理·数据挖掘·知识图谱
shansjqun10 小时前
教学内容全覆盖:航拍杂草检测与分类
人工智能·分类·数据挖掘
panpantt32111 小时前
【参会邀请】第二届大数据与数据挖掘国际会议(BDDM 2024)邀您相聚江城!
大数据·人工智能·数据挖掘
statistican_ABin12 小时前
R语言数据分析案例45-全国汽车销售数据分析(可视化与回归分析)
数据挖掘·数据分析