【问题标题】:How to copy training data n times during classification?如何在分类过程中复制训练数据 n 次?
【发布时间】:2017-05-01 16:39:25
【问题描述】:

我有一个分类问题,两个数据集分别有 200 分和 50 分。将这 40 个数据点中的一个作为测试集。考虑到五个最近邻,我选择了 kNN 作为分类器。

n_neighbors = 5
std = 5

# generate data

X0, y0 = make_blobs(n_samples=200, centers=2, n_features=2, cluster_std = std, random_state=42)
h = .1  # step size in the mesh

X1, y1 = make_blobs(n_samples=50, centers=2, n_features=2, cluster_std = std, random_state=42)

# split into training and test set
X0_train, X0_test, y0_train, y0_test = train_test_split(X0, y0, test_size=0.2, random_state=42)

X1_train, X1_test, y1_train, y1_test = train_test_split(X1, y1, test_size=0.2, random_state=42)

我必须以这样一种方式丰富数据,将第 1 类的训练数据复制 16 次,使第 1 类的训练规模与第 0 类相同。

如何将训练数据复制 16 次?我不知道这里的复制到底是什么意思。

谁能写几行代码来解释一下?

【问题讨论】:

    标签: python machine-learning classification knn training-data


    【解决方案1】:

    我猜你说的是类不平衡问题,为了克服这个问题,你需要做采样(上采样或下采样), 看看以下技术是否有帮助:(https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume16/chawla02a-html/chawla2002.html)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2016-07-03
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2013-08-30
      相关资源
      最近更新 更多