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


Python NearMiss.fit_sample方法代码示例

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


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

示例1: test_nm3_fit_sample_nn_obj

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_sample [as 别名]
def test_nm3_fit_sample_nn_obj():
    """Test fit-sample with nn object"""

    # Define the parameter for the under-sampling
    ratio = 'auto'

    # Create the object
    nn = NearestNeighbors(n_neighbors=3)
    nn3 = NearestNeighbors(n_neighbors=3)
    nm3 = NearMiss(
        ratio=ratio,
        random_state=RND_SEED,
        version=VERSION_NEARMISS,
        return_indices=True,
        n_neighbors=nn,
        n_neighbors_ver3=nn3)

    # Fit and sample
    X_resampled, y_resampled, idx_under = nm3.fit_sample(X, Y)

    X_gt = 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])
    idx_gt = np.array([3, 10, 11, 0, 2, 3, 5, 1, 4])
    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,代码行数:32,代码来源:test_nearmiss_3.py

示例2: test_multiclass_fit_sample

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss 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
    nm = NearMiss(random_state=RND_SEED, version=VERSION_NEARMISS)
    X_resampled, y_resampled = nm.fit_sample(X, y)

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

示例3: test_nm2_fit_sample_half

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_sample [as 别名]
def test_nm2_fit_sample_half():
    """Test fit and sample routines with .5 ratio"""

    # Define the parameter for the under-sampling
    ratio = .5

    # Create the object
    nm2 = NearMiss(ratio=ratio, random_state=RND_SEED,
                   version=VERSION_NEARMISS)

    # Fit and sample
    X_resampled, y_resampled = nm2.fit_sample(X, Y)

    currdir = os.path.dirname(os.path.abspath(__file__))
    X_gt = np.load(os.path.join(currdir, 'data', 'nm2_x_05.npy'))
    y_gt = np.load(os.path.join(currdir, 'data', 'nm2_y_05.npy'))
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:apyeh,项目名称:UnbalancedDataset,代码行数:20,代码来源:test_nearmiss_2.py

示例4: test_nm2_fit_sample_auto_indices

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_sample [as 别名]
def test_nm2_fit_sample_auto_indices():
    """Test fit and sample routines with auto ratio and indices support"""

    # Define the parameter for the under-sampling
    ratio = 'auto'

    # Create the object
    nm2 = NearMiss(ratio=ratio, random_state=RND_SEED,
                   version=VERSION_NEARMISS, return_indices=True)

    # Fit and sample
    X_resampled, y_resampled, idx_under = nm2.fit_sample(X, Y)

    currdir = os.path.dirname(os.path.abspath(__file__))
    X_gt = np.load(os.path.join(currdir, 'data', 'nm2_x.npy'))
    y_gt = np.load(os.path.join(currdir, 'data', 'nm2_y.npy'))
    idx_gt = np.load(os.path.join(currdir, 'data', 'nm2_idx.npy'))
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
    assert_array_equal(idx_under, idx_gt)
开发者ID:apyeh,项目名称:UnbalancedDataset,代码行数:22,代码来源:test_nearmiss_2.py

示例5: test_nm3_fit_sample_auto

# 需要导入模块: from imblearn.under_sampling import NearMiss [as 别名]
# 或者: from imblearn.under_sampling.NearMiss import fit_sample [as 别名]
def test_nm3_fit_sample_auto():
    """Test fit and sample routines with auto ratio"""

    # Define the parameter for the under-sampling
    ratio = 'auto'

    # Create the object
    nm3 = NearMiss(
        ratio=ratio, random_state=RND_SEED, version=VERSION_NEARMISS)

    # Fit and sample
    X_resampled, y_resampled = nm3.fit_sample(X, Y)

    X_gt = 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])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:23,代码来源:test_nearmiss_3.py


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