当前位置: 首页>>代码示例>>Python>>正文


Python RepeatedEditedNearestNeighbours.fit_sample方法代码示例

本文整理汇总了Python中imblearn.under_sampling.RepeatedEditedNearestNeighbours.fit_sample方法的典型用法代码示例。如果您正苦于以下问题:Python RepeatedEditedNearestNeighbours.fit_sample方法的具体用法?Python RepeatedEditedNearestNeighbours.fit_sample怎么用?Python RepeatedEditedNearestNeighbours.fit_sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imblearn.under_sampling.RepeatedEditedNearestNeighbours的用法示例。


在下文中一共展示了RepeatedEditedNearestNeighbours.fit_sample方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_renn_fit_sample_mode

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_fit_sample_mode():
    """Test the fit sample routine using the mode as selection"""

    # Resample the data
    nn = NearestNeighbors(n_neighbors=4)
    renn = RepeatedEditedNearestNeighbours(
        n_neighbors=nn, random_state=RND_SEED, kind_sel='mode')
    X_resampled, y_resampled = renn.fit_sample(X, Y)

    X_gt = np.array([[-0.53171468, -0.53735182], [-0.88864036, -0.33782387],
                     [-0.46226554, -0.50481004], [-0.34474418, 0.21969797],
                     [-0.12840393, 0.66446571], [1.02956816, 0.36061601],
                     [1.12202806, 0.33811558], [-0.35946678, 0.72510189],
                     [2.94290565, -0.13986434], [-1.10146139, 0.91782682],
                     [0.73489726, 0.43915195], [-0.28479268, 0.70459548],
                     [1.84864913, 0.14729596], [0.50307437, 0.498805],
                     [0.84929742, 0.41042894], [0.62649535, 0.46600596],
                     [1.67314371, 0.19231498], [0.98382284, 0.37184502],
                     [0.69804044, 0.44810796], [1.32319756, -0.13181616],
                     [0.04296502, -0.37981873], [0.28294738, -1.00125525],
                     [0.34218094, -0.58781961], [0.2096964, -0.61814058],
                     [1.59068979, -0.96622933], [0.73418199, -0.02222847],
                     [0.79270821, -0.41386668], [1.16606871, -0.25641059],
                     [1.0304995, -0.16955962], [0.48921682, -1.38504507],
                     [-0.03918551, -0.68540745], [0.24991051, -1.00864997],
                     [0.80541964, -0.34465185], [0.1732627, -1.61323172]])
    y_gt = np.array([
        0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
        2, 2, 2, 2, 2, 2, 2, 2, 2, 2
    ])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:34,代码来源:test_repeated_edited_nearest_neighbours.py

示例2: test_renn_fit_sample_with_indices

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_fit_sample_with_indices():
    """Test the fit sample routine with indices support"""

    # Resample the data
    renn = RepeatedEditedNearestNeighbours(
        return_indices=True, random_state=RND_SEED)
    X_resampled, y_resampled, idx_under = renn.fit_sample(X, Y)

    X_gt = np.array([[-0.53171468, -0.53735182], [-0.88864036, -0.33782387],
                     [-0.46226554, -0.50481004], [-0.34474418, 0.21969797],
                     [1.02956816, 0.36061601], [1.12202806, 0.33811558],
                     [0.73489726, 0.43915195], [0.50307437, 0.498805],
                     [0.84929742, 0.41042894], [0.62649535, 0.46600596],
                     [0.98382284, 0.37184502], [0.69804044, 0.44810796],
                     [0.04296502, -0.37981873], [0.28294738, -1.00125525],
                     [0.34218094, -0.58781961], [0.2096964, -0.61814058],
                     [1.59068979, -0.96622933], [0.73418199, -0.02222847],
                     [0.79270821, -0.41386668], [1.16606871, -0.25641059],
                     [1.0304995, -0.16955962], [0.48921682, -1.38504507],
                     [-0.03918551, -0.68540745], [0.24991051, -1.00864997],
                     [0.80541964, -0.34465185], [0.1732627, -1.61323172]])
    y_gt = np.array([
        0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        2, 2
    ])
    idx_gt = np.array([
        6, 13, 32, 39, 4, 5, 16, 22, 23, 24, 30, 37, 2, 11, 12, 17, 20, 21, 25,
        26, 28, 31, 33, 34, 35, 36
    ])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
    assert_array_equal(idx_under, idx_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:34,代码来源:test_repeated_edited_nearest_neighbours.py

示例3: test_renn_fit_sample

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_fit_sample():
    """Test the fit sample routine"""

    # Resample the data
    renn = RepeatedEditedNearestNeighbours(random_state=RND_SEED)
    X_resampled, y_resampled = renn.fit_sample(X, Y)

    currdir = os.path.dirname(os.path.abspath(__file__))
    X_gt = np.load(os.path.join(currdir, 'data', 'renn_x.npy'))
    y_gt = np.load(os.path.join(currdir, 'data', 'renn_y.npy'))
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:integrallyclosed,项目名称:imbalanced-learn,代码行数:14,代码来源:test_repeated_edited_nearest_neighbours.py

示例4: test_renn_fit_sample_with_indices

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_fit_sample_with_indices():
    """Test the fit sample routine with indices support"""

    # Resample the data
    renn = RepeatedEditedNearestNeighbours(return_indices=True,
                                           random_state=RND_SEED)
    X_resampled, y_resampled, idx_under = renn.fit_sample(X, Y)

    currdir = os.path.dirname(os.path.abspath(__file__))
    X_gt = np.load(os.path.join(currdir, 'data', 'renn_x.npy'))
    y_gt = np.load(os.path.join(currdir, 'data', 'renn_y.npy'))
    idx_gt = np.load(os.path.join(currdir, 'data', 'renn_idx.npy'))
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
    assert_array_equal(idx_under, idx_gt)
开发者ID:integrallyclosed,项目名称:imbalanced-learn,代码行数:17,代码来源:test_repeated_edited_nearest_neighbours.py

示例5: test_multiclass_fit_sample

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_multiclass_fit_sample():
    """Test fit sample method with multiclass target"""

    # Make y to be multiclass
    y = Y.copy()
    y[0:1000] = 2

    # Resample the data
    enn = RepeatedEditedNearestNeighbours(random_state=RND_SEED)
    X_resampled, y_resampled = enn.fit_sample(X, y)

    # Check the size of y
    count_y_res = Counter(y_resampled)
    assert_equal(count_y_res[0], 378)
    assert_equal(count_y_res[1], 1828)
    assert_equal(count_y_res[2], 5)
开发者ID:integrallyclosed,项目名称:imbalanced-learn,代码行数:18,代码来源:test_repeated_edited_nearest_neighbours.py

示例6: test_renn_fit_sample

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_fit_sample():
    renn = RepeatedEditedNearestNeighbours()
    X_resampled, y_resampled = renn.fit_sample(X, Y)

    X_gt = np.array([[-0.53171468, -0.53735182], [-0.88864036, -0.33782387],
                     [-0.46226554, -0.50481004], [-0.34474418, 0.21969797],
                     [1.02956816, 0.36061601], [1.12202806, 0.33811558],
                     [0.73489726, 0.43915195], [0.50307437, 0.498805],
                     [0.84929742, 0.41042894], [0.62649535, 0.46600596],
                     [0.98382284, 0.37184502], [0.69804044, 0.44810796],
                     [0.04296502, -0.37981873], [0.28294738, -1.00125525],
                     [0.34218094, -0.58781961], [0.2096964, -0.61814058],
                     [1.59068979, -0.96622933], [0.73418199, -0.02222847],
                     [0.79270821, -0.41386668], [1.16606871, -0.25641059],
                     [1.0304995, -0.16955962], [0.48921682, -1.38504507],
                     [-0.03918551, -0.68540745], [0.24991051, -1.00864997],
                     [0.80541964, -0.34465185], [0.1732627, -1.61323172]])
    y_gt = np.array([
        0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        2, 2
    ])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:25,代码来源:test_repeated_edited_nearest_neighbours.py

示例7: print

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
X_resampled, y_resampled = enn.fit_sample(X, y)
X_res_vis = pca.transform(X_resampled)
print('Reduced {:.2f}\%'.format(100 * (1 - float(len(X_resampled))/ len(X))))

ax2.scatter(X_res_vis[y_resampled == 0, 0], X_res_vis[y_resampled == 0, 1],
            label="Class #0", alpha=.5, edgecolor=almost_black,
            facecolor=palette[0], linewidth=0.15)
ax2.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],
            label="Class #1", alpha=.5, edgecolor=almost_black,
            facecolor=palette[2], linewidth=0.15)
ax2.set_title('Edited nearest neighbours')

# Apply the RENN
print('RENN')
renn = RepeatedEditedNearestNeighbours()
X_resampled, y_resampled = renn.fit_sample(X, y)
X_res_vis = pca.transform(X_resampled)
print('Reduced {:.2f}\%'.format(100 * (1 - float(len(X_resampled))/ len(X))))

ax3.scatter(X_res_vis[y_resampled == 0, 0], X_res_vis[y_resampled == 0, 1],
            label="Class #0", alpha=.5, edgecolor=almost_black,
            facecolor=palette[0], linewidth=0.15)
ax3.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],
            label="Class #1", alpha=.5, edgecolor=almost_black,
            facecolor=palette[2], linewidth=0.15)
ax3.set_title('Repeated Edited nearest neighbours')

# Apply the AllKNN
print('AllKNN')
allknn = AllKNN()
X_resampled, y_resampled = allknn.fit_sample(X, y)
开发者ID:dvro,项目名称:imbalanced-learn,代码行数:33,代码来源:plot_allknn.py

示例8: test_renn_iter_wrong

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_iter_wrong():
    max_iter = -1
    renn = RepeatedEditedNearestNeighbours(max_iter=max_iter)
    with raises(ValueError):
        renn.fit_sample(X, Y)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:7,代码来源:test_repeated_edited_nearest_neighbours.py

示例9: test_deprecation_random_state

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_deprecation_random_state():
    renn = RepeatedEditedNearestNeighbours(random_state=0)
    with warns(DeprecationWarning,
               match="'random_state' is deprecated from 0.4"):
        renn.fit_sample(X, Y)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:7,代码来源:test_repeated_edited_nearest_neighbours.py

示例10: test_renn_not_good_object

# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_sample [as 别名]
def test_renn_not_good_object():
    nn = 'rnd'
    renn = RepeatedEditedNearestNeighbours(
        n_neighbors=nn, kind_sel='mode')
    with raises(ValueError):
        renn.fit_sample(X, Y)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:8,代码来源:test_repeated_edited_nearest_neighbours.py


注:本文中的imblearn.under_sampling.RepeatedEditedNearestNeighbours.fit_sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。