Skip to content

Instantly share code, notes, and snippets.

@anxingle
Created December 22, 2020 01:29
Show Gist options
  • Save anxingle/2b6a3be40432542f9013abac4fa6de95 to your computer and use it in GitHub Desktop.
Save anxingle/2b6a3be40432542f9013abac4fa6de95 to your computer and use it in GitHub Desktop.
smo data
# 生成测试数据,训练样本
X_train, y = make_blobs(n_samples = 1000, centers =2, n_features=2, random_state = 2)
# StandardScaler()以及fit_transfrom函数的作用需要解释一下
scaler = StandardScaler() #数据预处理,使得经过处理的数据符合正态分布,即均值为0,标准差为1
X_train_scaled = scaler.fit_transform(X_train, y)
y[y == 0] = -1
# 将训练数据绘制出来
fig, ax = plt.subplots()
ax.scatter(X_train_scaled[:, 0], X_train_scaled[:, 1],
c=y, cmap=plt.cm.viridis, lw=0, alpha =0.25)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment