Fisher 分数错误 - 值的长度与索引的长度不匹配?

Fisher score error - Length of value does not match length of index?

我正在处理 ML 问题,尝试计算 Fisher 分数以用于特征选择

A B Y
1 1 1
2 5 1
1 5 1
7 9 0
7 9 0
8 9 0

t = pd.read_clipboard()

我正在尝试计算每个特征的 Fisher 分数。我只是按照原样学习教程 here and here

代码如下

!pip install skfeature-chappers
from skfeature.function.similarity_based import fisher_score
score = fisher_score.fisher_score(t[['A','B']], t['Y'])) # error here
score = fisher_score.fisher_score(t[['A','B']], t['Y']), mode='rank') # tried this but also error
score = pd.Series(fisher_score.fisher_score(t[['A','B']], t['Y']))) # error here

我明白了

ValueError: Length of values (1) does not match length of index (2)

如果我只传递一个特征作为输入,如下所示,

score = pd.Series(fisher_score.fisher_score(t[['A']], t['Y']))

我希望我的输出包含每个功能的分数列表,但我收到另一个错误:

ValueError: Data must be 1-dimensional

如何解决这个问题?

fisher_score 方法的输入应该是一个 numpy 数组,而不是 pandas dataframe/series。

试试这个:

score = fisher_score.fisher_score(t[['A','B']].to_numpy(),
                      t['Y'].to_numpy())