Machine learning 绘图数据集
我需要创建自己的数据来开发分类器,但我不知道如何创建。非常感谢您的帮助。您只需创建具有特定平均值和标准的法线即可Machine learning 绘图数据集,machine-learning,data-visualization,Machine Learning,Data Visualization,我需要创建自己的数据来开发分类器,但我不知道如何创建。非常感谢您的帮助。您只需创建具有特定平均值和标准的法线即可 import numpy as np import matplotlib.pyplot as plt std = [[0.5, 0], [0, 0.5]] X1 = np.random.multivariate_normal([2, -2], std, size=100) X2 = np.random.multivariate_normal([-2, 2], std, size=1
import numpy as np
import matplotlib.pyplot as plt
std = [[0.5, 0], [0, 0.5]]
X1 = np.random.multivariate_normal([2, -2], std, size=100)
X2 = np.random.multivariate_normal([-2, 2], std, size=100)
X = np.vstack((X1, X2))
Y1 = np.random.multivariate_normal([2, 2], std, size=100)
Y2 = np.random.multivariate_normal([-2, -2], std, size=100)
Y = np.vstack((Y1, Y2))
plt.scatter(X[:, 0], X[:, 1])
plt.scatter(Y[:, 0], Y[:, 1])
plt.show()
通过使用,您可以非常有效地做到这一点 它生成一个随机的
n类分类问题,具有很多选项和高度灵活性
例如:
X, y = make_classification(n_samples=100, n_features=2, n_informative=2,
n_redundant=0, n_repeated=0, n_clusters_per_class=1,
n_classes=2, shuffle=True, random_state=2021)
上面的一行代码创建了一个包含100个样本、2个特征(所有特征都是信息性的)、2个类和每个类1个集群的数据集,然后对它们进行洗牌。random_state
只是为了使过程重现
然后可以将其绘制为:
plt.scatter(X[:, 0], X[:, 1], marker='o', c=y, s=25, edgecolor='k')
plt.show()
输出外观的示例: