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


Python NearMiss.fit_resample方法代码示例

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


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

示例1: test_nm_fit_resample_auto

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_resample [as 别名]
def test_nm_fit_resample_auto():
    sampling_strategy = 'auto'
    X_gt = [
        np.array([[0.91464286, 1.61369212], [-0.80809175, -1.09917302], [
            -0.20497017, -0.26630228
        ], [-0.05903827, 0.10947647], [0.03142011, 0.12323596],
                  [-0.60413357, 0.24628718], [0.50701028, -0.17636928],
                  [0.4960075, 0.86130762], [0.45713638, 1.31069295]]),
        np.array([[0.91464286, 1.61369212], [-0.80809175, -1.09917302], [
            -0.20497017, -0.26630228
        ], [-0.05903827, 0.10947647], [0.03142011, 0.12323596],
                  [-0.60413357, 0.24628718], [0.50701028, -0.17636928],
                  [0.4960075, 0.86130762], [0.45713638, 1.31069295]]),
        np.array([[0.91464286, 1.61369212], [-0.80809175, -1.09917302], [
            -0.20497017, -0.26630228
        ], [1.17737838, -0.2002118], [-0.60413357, 0.24628718],
                  [0.03142011, 0.12323596], [1.15157493, -1.2981518],
                  [-0.54619583, 1.73009918], [0.99272351, -0.11631728]])
    ]
    y_gt = [
        np.array([0, 0, 0, 1, 1, 1, 2, 2, 2]),
        np.array([0, 0, 0, 1, 1, 1, 2, 2, 2]),
        np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
    ]
    for version_idx, version in enumerate(VERSION_NEARMISS):
        nm = NearMiss(sampling_strategy=sampling_strategy, version=version)
        X_resampled, y_resampled = nm.fit_resample(X, Y)
        assert_array_equal(X_resampled, X_gt[version_idx])
        assert_array_equal(y_resampled, y_gt[version_idx])
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:31,代码来源:test_nearmiss.py

示例2: test_nm_wrong_nn_obj

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_resample [as 别名]
def test_nm_wrong_nn_obj():
    sampling_strategy = 'auto'
    nn = 'rnd'
    nm = NearMiss(
        sampling_strategy=sampling_strategy,
        version=VERSION_NEARMISS,
        return_indices=True,
        n_neighbors=nn)
    with raises(ValueError, match="has to be one of"):
        nm.fit_resample(X, Y)
    nn3 = 'rnd'
    nn = NearestNeighbors(n_neighbors=3)
    nm3 = NearMiss(
        sampling_strategy=sampling_strategy,
        version=3,
        return_indices=True,
        n_neighbors=nn,
        n_neighbors_ver3=nn3)
    with raises(ValueError, match="has to be one of"):
        nm3.fit_resample(X, Y)
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:22,代码来源:test_nearmiss.py

示例3: test_nearmiss_wrong_version

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_resample [as 别名]
def test_nearmiss_wrong_version():
    version = 1000
    nm = NearMiss(version=version)
    with raises(ValueError, match="must be 1, 2 or 3"):
        nm.fit_resample(X, Y)
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:7,代码来源:test_nearmiss.py

示例4: test_deprecation_random_state

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


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