2012-11-17 33 views
1

下面是從數據集中選擇一定數量的隨機排列的示例,我如何使用remaainder創建新的數據集。例如,在下面的例子中,我選擇49402(大約10%)並在選擇這個數據集後創建一個名爲UnseenTestdata的數據集。我希望剩餘的數據集進入一個名爲testdata的新數據集。如何獲取數據集的其餘部分

pointsToPick = 49402; %# Numbers to pick 
rVec = randperm(494021); %# Random permutation of datapoint indices (N=494021 in this case) 

UnseenTestdata = fulldata(rVec(1:pointsToPick),:); %# Random sample 

Unseentestdata minus全數據=恰當地命名爲testdata的數據集的其餘部分。

完整數據集的尺寸爲494021x6,其中我從全數據中隨機選擇49402x6。然後我需要從完整數據中減去未經驗證的數據。

巴拿巴索博爾奇添加的測試用例答案:

fulldata = [1 2; 3 4; 5 6; 7 8]; 
rVec = randperm(4); 
pointsToPick=2; 
unseen = fulldata(rVec(1:pointsToPick),:); 
testdata = fulldata(rVec(pointsToPick:length(rVec)),:); 

然而,這並不工作,我已經屏甩結果:

enter image description here

如果您在屏幕轉儲看不見的通知數據= 3,4和7,8然而,如果你注意到測試數據7,8仍然存在。

如果fulldata =

1,2 
3,4 
5,6 
7,8 

而我們在這種情況下,選擇兩個隨機排在看不見的行是:

row 
3,4 
7,8 

那麼無論遺骸應該是:

1,2 
5,6 

然而如果您注意到在示例測試testdata的sreen轉儲中有以下行:

7,8 

顯示示例測試不起作用。

+0

你的意思是setminus這裏不要你?你還可以添加完整數據的維度嗎? –

+0

更新了我的答案,還加入了測試用例來驗證。 –

+0

我希望你再次檢查我的答案,對不起,我對這些括號很sl。。 Plus也更新了測試用例,因爲它具有剩餘元素數量和全部數據的第二維度相等的特性。 –

回答

0

如果我正確理解你的問題,解決的辦法是

testdata = fulldata(rVec((pointsToPick+1):length(rVec)),:); 

簡單的測試案例:

fulldata = [1 2; 3 4; 5 6; 7 8;10 9]; 
rVec = randperm(4); // gives me first time [4 2 3 1 5] 
pointsToPick=2; 
unseen = fulldata(rVec(1:pointsToPick),:); // [7 8; 3 4] 
// length(rVec) is 5 
testdata = fulldata(rVec((pointsToPick+1):length(rVec)),:); // [5 6; 1 2; 10 9] 

,你可以清楚地看到,在某種意義上fulldata = unseen(setplus)testdata。 請注意,我們需要「+1」,因爲數組索引從1開始不同於C++中的說法,所以最後的索引是length而不是length-1

您可以驗證,如果事情是使用這個正確的:

isequal(sort([unseen; test]), sort(full_data)) // should be true 
+0

嗯什麼東西是可疑的,測試數據的輸出是444620,當它應該是444619。 –

+0

是的,已更正。 –

+0

哈哈,你不能只是做+1,可以嗎?我需要的數據是確切的,即unseentestdata減去fulldata =餘數。它可能需要索引unseentestdata。長度等可能不是我想要的。 –

相關問題