最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python?sklearn?中的?make_blobs()?函數(shù)示例詳解

 更新時(shí)間:2023年02月22日 11:33:00   作者:旅途中的寬~  
make_blobs()?是?sklearn.datasets中的一個(gè)函數(shù),這篇文章主要介紹了Python?sklearn?中的?make_blobs()?函數(shù),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

一、介紹

make_blobs() 是 sklearn.datasets中的一個(gè)函數(shù)。

主要是產(chǎn)生聚類數(shù)據(jù)集,產(chǎn)生一個(gè)數(shù)據(jù)集和相應(yīng)的標(biāo)簽。

函數(shù)的源代碼如下:

def 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):
    """Generate isotropic Gaussian blobs for clustering.

    Read more in the :ref:`User Guide <sample_generators>`.

    Parameters
    ----------
    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.

    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`.

    Returns
    -------
    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.

    Examples
    --------
    >>> from sklearn.datasets.samples_generator import make_blobs
    >>> X, y = make_blobs(n_samples=10, centers=3, n_features=2,
    ...                   random_state=0)
    >>> print(X.shape)
    (10, 2)
    >>> y
    array([0, 0, 1, 0, 2, 2, 2, 1, 1, 0])

    See also
    --------
    make_classification: a more intricate variant
    """
    generator = check_random_state(random_state)

    if isinstance(centers, numbers.Integral):
        centers = generator.uniform(center_box[0], center_box[1],
                                    size=(centers, n_features))
    else:
        centers = check_array(centers)
        n_features = centers.shape[1]

    if isinstance(cluster_std, numbers.Real):
        cluster_std = np.ones(len(centers)) * cluster_std

    X = []
    y = []

    n_centers = centers.shape[0]
    n_samples_per_center = [int(n_samples // n_centers)] * n_centers

    for i in range(n_samples % n_centers):
        n_samples_per_center[i] += 1

    for i, (n, std) in enumerate(zip(n_samples_per_center, cluster_std)):
        X.append(centers[i] + generator.normal(scale = std,
                                               size = (n, n_features)))
        y += [i] * n

    X = np.concatenate(X)
    y = np.array(y)

    if shuffle:
        indices = np.arange(n_samples)
        generator.shuffle(indices)
        X = X[indices]
        y = y[indices]

    return X, y

二、函數(shù)的使用

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)

可以看到它有 7 個(gè)參數(shù):

  • n_samples = 100 ,表示數(shù)據(jù)樣本點(diǎn)個(gè)數(shù),默認(rèn)值100;
  • n_features = 2 ,是每個(gè)樣本的特征(或?qū)傩裕?shù),也表示數(shù)據(jù)的維度,默認(rèn)值是2;
  • centers = 3 ,表示類別數(shù)(標(biāo)簽的種類數(shù)),默認(rèn)值3;
  • cluster_std = 1.0 ,表示每個(gè)類別的方差,例如我們希望生成2類數(shù)據(jù),其中一類比另一類具有更大的方差,可以將cluster_std設(shè)置為[1.0, 3.0],浮點(diǎn)數(shù)或者浮點(diǎn)數(shù)序列,默認(rèn)值1.0;
  • center_box = (-10.0, 10.0) ,中心確定之后的數(shù)據(jù)邊界,默認(rèn)值(-10.0, 10.0);
  • shuffle = True ,將數(shù)據(jù)進(jìn)行洗亂,默認(rèn)值是True;
  • random_state = None ,官網(wǎng)解釋是隨機(jī)生成器的種子,可以固定生成的數(shù)據(jù),給定數(shù)之后,每次生成的數(shù)據(jù)集就是固定的。若不給定值,則由于隨機(jī)性將導(dǎo)致每次運(yùn)行程序所獲得的的結(jié)果可能有所不同。在使用數(shù)據(jù)生成器練習(xí)機(jī)器學(xué)習(xí)算法練習(xí)或python練習(xí)時(shí)建議給定數(shù)值。

到此這篇關(guān)于Python sklearn 中的 make_blobs() 函數(shù)詳解的文章就介紹到這了,更多相關(guān)Python sklearn make_blobs() 函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

建始县| 临海市| 马龙县| 海宁市| 白山市| 滕州市| 原阳县| 花垣县| 营山县| 昌乐县| 封开县| 乐安县| 安图县| 应用必备| 庆云县| 安图县| 封开县| 宿迁市| 科尔| 和政县| 泸定县| 清河县| 紫阳县| 淮阳县| 宣汉县| 沙河市| 冀州市| 门头沟区| 乐昌市| 吴忠市| 庆阳市| 平邑县| 黄冈市| 荆门市| 无棣县| 六安市| 海盐县| 霍州市| 中牟县| 大邑县| 新竹市|