欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)生聚類(lèi)數(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 ,表示類(lèi)別數(shù)(標(biāo)簽的種類(lèi)數(shù)),默認(rèn)值3;
  • cluster_std = 1.0 ,表示每個(gè)類(lèi)別的方差,例如我們希望生成2類(lèi)數(shù)據(jù),其中一類(lèi)比另一類(lèi)具有更大的方差,可以將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)文章

  • Python閉包技巧介紹

    Python閉包技巧介紹

    這篇文章主要介紹了Python閉包,所謂閉包就是用函數(shù)代替類(lèi),被外層函數(shù)包圍的內(nèi)層函數(shù),它能夠獲取外層函數(shù)范圍中的變量,感興趣的小伙伴請(qǐng)和小編一起進(jìn)入文章學(xué)習(xí)具體內(nèi)容吧
    2021-12-12
  • Python如何用字典完成匹配任務(wù)

    Python如何用字典完成匹配任務(wù)

    在生物信息學(xué)領(lǐng)域,經(jīng)常需要根據(jù)基因名稱(chēng)匹配其對(duì)應(yīng)的編號(hào),本文介紹了一種通過(guò)字典進(jìn)行基因名稱(chēng)與編號(hào)匹配的方法,首先定義一個(gè)空列表存儲(chǔ)對(duì)應(yīng)編號(hào),對(duì)于字典中不存在的基因名稱(chēng),其編號(hào)默認(rèn)為0
    2024-09-09
  • Python函數(shù)中的函數(shù)(閉包)用法實(shí)例

    Python函數(shù)中的函數(shù)(閉包)用法實(shí)例

    這篇文章主要介紹了Python函數(shù)中的函數(shù)(閉包)用法,結(jié)合實(shí)例形式分析了Python閉包的定義與使用技巧,需要的朋友可以參考下
    2016-03-03
  • python找出列表中大于某個(gè)閾值的數(shù)據(jù)段示例

    python找出列表中大于某個(gè)閾值的數(shù)據(jù)段示例

    今天小編就為大家分享一篇python找出列表中大于某個(gè)閾值的數(shù)據(jù)段示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-11-11
  • python類(lèi)中的self和變量用法及說(shuō)明

    python類(lèi)中的self和變量用法及說(shuō)明

    這篇文章主要介紹了python類(lèi)中的self和變量用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Python heapq庫(kù)案例詳解

    Python heapq庫(kù)案例詳解

    這篇文章主要介紹了Python heapq庫(kù)案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • 詳解Python字符串原理與使用的深度總結(jié)

    詳解Python字符串原理與使用的深度總結(jié)

    本文將學(xué)習(xí)字符串?dāng)?shù)據(jù)類(lèi)型相關(guān)知識(shí),將討論如何聲明字符串?dāng)?shù)據(jù)類(lèi)型,字符串?dāng)?shù)據(jù)類(lèi)型與?ASCII?表的關(guān)系,字符串?dāng)?shù)據(jù)類(lèi)型的屬性,以及一些重要的字符串方法和操作,超級(jí)干貨,不容錯(cuò)過(guò)
    2022-05-05
  • Python中的sorted函數(shù)使用解析

    Python中的sorted函數(shù)使用解析

    這篇文章主要介紹了Python中的sorted函數(shù)使用解析,sorted()函數(shù)可以對(duì)可迭代對(duì)象進(jìn)行排序,并且可以人為指定排序的依據(jù)以及方式,本文提供了解決與部分實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2023-10-10
  • Python實(shí)現(xiàn)蒙特卡洛算法小實(shí)驗(yàn)過(guò)程詳解

    Python實(shí)現(xiàn)蒙特卡洛算法小實(shí)驗(yàn)過(guò)程詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)基于蒙特卡洛算法過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • Flask框架中request、請(qǐng)求鉤子、上下文用法分析

    Flask框架中request、請(qǐng)求鉤子、上下文用法分析

    這篇文章主要介紹了Flask框架中request、請(qǐng)求鉤子、上下文用法,結(jié)合實(shí)例形式分析了flask框架中request、請(qǐng)求鉤子及上下文的功能、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-07-07

最新評(píng)論