日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

【Python学习】 - sklearn - 用于生成数据的make_blobs模块

發(fā)布時(shí)間:2023/12/10 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Python学习】 - sklearn - 用于生成数据的make_blobs模块 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

函數(shù)原型:

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)

?

參數(shù)含義:

n_samples: int, optional (default=100)
The total number of points equally divided among clusters.
待生成的樣本的總數(shù)。
n_features: int, optional (default=2)
The number of features for each sample.
每個(gè)樣本的特征數(shù)。
centers: int or array of shape [n_centers, n_features], optional (default=3)
The number of centers to generate, or the fixed center locations.
要生成的樣本中心(類別)數(shù),或者是確定的中心點(diǎn)。
cluster_std: float or sequence of floats, optional (default=1.0)
The standard deviation of the clusters.
每個(gè)類別的方差,例如我們希望生成2類數(shù)據(jù),其中一類比另一類具有更大的方差,可以將cluster_std設(shè)置為[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.
生成的樣本數(shù)據(jù)集。
y : array of shape [n_samples]
The integer labels for cluster membership of each sample.
樣本數(shù)據(jù)集的標(biāo)簽。

?

實(shí)戰(zhàn)代碼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個(gè)樣本,每個(gè)樣本3個(gè)特征,共4個(gè)簇 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()

輸出:?

?

實(shí)戰(zhàn)代碼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()

輸出:

總結(jié)

以上是生活随笔為你收集整理的【Python学习】 - sklearn - 用于生成数据的make_blobs模块的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。