微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

生成具有不平衡率和扰动率 (DR) 的数据

如何解决生成具有不平衡率和扰动率 (DR) 的数据

我想生成具有不平衡率 (IR) 和干扰率 (DR) 的数据。不平衡比(IR)用于衡量不平衡程度,其定义为多数类的样本数除以少数类的样本数。干扰比表示类之间的重叠程度。我有兴趣生成如图所示的数据。谢谢你的时间! Synthetic datasets with IR= 5 and DR= 70%

# vary the number of clusters for a 1:100 imbalanced dataset
from collections import Counter
from sklearn.datasets import make_classification
from matplotlib import pyplot
from numpy import where
# number of clusters
clusters = [1,2]
# create and plot a dataset with different numbers of clusters
for i in range(len(clusters)):
    c = clusters[i]
    # define dataset
    X,y = make_classification(n_samples=10000,n_features=2,n_redundant=0,n_clusters_per_class=c,weights=[0.99],flip_y=0,random_state=1)
    counter = Counter(y)
    # define subplot
    pyplot.subplot(1,2,1+i)
    pyplot.title('Clusters=%d' % c)
    pyplot.xticks([])
    pyplot.yticks([])
    # scatter plot of examples by class label
    for label,_ in counter.items():
        row_ix = where(y == label)[0]
        pyplot.scatter(X[row_ix,0],X[row_ix,1],label=str(label))
    pyplot.legend()
# show the figure
pyplot.show()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。