我正在研究 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()
我正在嘗試計算每個功能的費希爾分數。我只是按照這里和這里的教程進行操作
代碼如下
!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
如何解決這個問題?
uj5u.com熱心網友回復:
fisher_score 方法的輸入應該是一個 numpy 陣列,而不是 pandas 資料幀/系列。
嘗試這個:
score = fisher_score.fisher_score(t[['A','B']].to_numpy(),
t['Y'].to_numpy())
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/436980.html
標籤:Python 熊猫 机器学习 scikit-学习 特征选择
