【Python学习】 - sklearn - 用于生成数据的make_blobs模块
函數原型:
sklearn.datasets.make_blobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None)
?
參數含義:
n_samples: int, optional (default=100)
The total number of points equally divided among clusters.
待生成的樣本的總數。
n_features: int, optional (default=2)
The number of features for each sample.
每個樣本的特征數。
centers: int or array of shape [n_centers, n_features], optional (default=3)
The number of centers to generate, or the fixed center locations.
要生成的樣本中心(類別)數,或者是確定的中心點。
cluster_std: float or sequence of floats, optional (default=1.0)
The standard deviation of the clusters.
每個類別的方差,例如我們希望生成2類數據,其中一類比另一類具有更大的方差,可以將cluster_std設置為[1.0,3.0]。
center_box: pair of floats (min, max), optional (default=(-10.0, 10.0))
The bounding box for each cluster center when centers are generated at random.
shuffle: boolean, optional (default=True)
Shuffle the samples.
random_state: int, RandomState instance or None, optional (default=None)
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.
?
返回值
X : array of shape [n_samples, n_features]
The generated samples.
生成的樣本數據集。
y : array of shape [n_samples]
The integer labels for cluster membership of each sample.
樣本數據集的標簽。
?
實戰代碼1:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from sklearn.datasets.samples_generator import make_blobs # X為樣本特征,Y為樣本簇類別, 共1000個樣本,每個樣本3個特征,共4個簇 X, y = make_blobs(n_samples=10000, n_features=3, centers=[[3,3, 3], [0,0,0], [1,1,1], [2,2,2]], cluster_std=[0.2, 0.1, 0.2, 0.2], random_state =9) fig = plt.figure() ax = Axes3D(fig, rect=[0, 0, 1, 1], elev=30, azim=20) plt.scatter(X[:, 0], X[:, 1], X[:, 2],marker='o') plt.show()輸出:?
?
實戰代碼2:
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets.samples_generator import make_blobsX, y = make_blobs(n_samples=100, n_features=2, centers=4)plt.scatter(X[:, 0], X[:, 1], c='b') plt.show()輸出:
總結
以上是生活随笔為你收集整理的【Python学习】 - sklearn - 用于生成数据的make_blobs模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 9元小白理财训练营是骗局吗?12天小白理
- 下一篇: CCNA-第十六篇-综合实验