對於任務,我必須使用屬於某些數據的功能的不同組合來評估分類系統。通過特徵我的意思是測量,例如身高,體重,年齡,收入。因此,舉個例子,我想看看分類器在給定高度和重量的情況下的表現如何,然後根據身高和年齡表示。我不僅希望能夠測試哪兩種功能最好地協同工作,而且還希望將3個功能最好地結合在一起,並且希望能夠將其推廣到n功能。使用Python的功能組合NumPy
我一直在嘗試使用numpy的mgrid,創建n維數組,將它們展平,然後創建使用每個數組中相同元素創建新數組的數組。棘手的所以這裏解釋一下是一些代碼和僞代碼:
import numpy as np
def test_feature_combos(data, combinations):
dimensions = combinations.shape[0]
grid = np.empty(dimensions)
for i in xrange(dimensions):
grid[i] = combinations[i].flatten()
#The above code throws an error "setting an array element with a sequence" error which I understand, but this shows my approach.
**Pseudo code begin**
For each element of each element of this new array,
create a new array like so:
[[1,1,2,2],[1,2,1,2]] ---> [[1,1],[1,2],[2,1],[2,2]]
Call this new array combo_indices
Then choose the columns (features) from the data in a loop using:
new_data = data[:, combo_indices[j]]
combinations = np.mgrid[1:5,1:5]
test_feature_combos(data, combinations)
我承認,這種做法意味着很多是由於重複不必要的組合,但我甚至無法實現這個乞丐所以不能挑肥揀瘦。
請有人建議我如何能a)實現我的方法或b)以更加優雅的方式實現這一目標。
在此先感謝,並告知我是否需要澄清,這很難解釋。
你能否提供一些樣本'數據'和'組合'供人們玩耍? – jkalden