[英]random subsampling of the majority class
假設您的數據看起來像從這段代碼生成的東西:
import numpy as np
x = np.random.randn(100, 3)
y = np.array([int(i % 5 == 0) for i in range(100)])
(只有 1/5 的y
是 1,這是少數類)。
要找到少數類的大小,請執行以下操作:
>>> np.sum(y == 1)
20
要找到包含多數類的子集,請執行以下操作:
majority_x, majority_y = x[y == 0, :], y[y == 0]
要找到大小為 20 的隨機子集,請執行以下操作:
inds = np.random.choice(range(majority_x.shape[0]), 20)
其次是
majority_x[inds, :]
和
majority_y[inds]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.