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


Python under_sampling.RepeatedEditedNearestNeighbours类代码示例

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


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

示例1: test_renn_fit_resample

def test_renn_fit_resample():
    renn = RepeatedEditedNearestNeighbours()
    X_resampled, y_resampled = renn.fit_resample(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:chkoar,项目名称:imbalanced-learn,代码行数:26,代码来源:test_repeated_edited_nearest_neighbours.py

示例2: test_renn_fit_sample_mode

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,代码行数:32,代码来源:test_repeated_edited_nearest_neighbours.py

示例3: test_renn_fit_sample_with_indices

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,代码行数:32,代码来源:test_repeated_edited_nearest_neighbours.py

示例4: test_renn_sample_wrong_X

def test_renn_sample_wrong_X():
    """Test either if an error is raised when X is different at fitting
    and sampling"""

    # Create the object
    renn = RepeatedEditedNearestNeighbours(random_state=RND_SEED)
    renn.fit(X, Y)
    assert_raises(RuntimeError, renn.sample,
                  np.random.random((100, 40)), np.array([0] * 50 + [1] * 50))
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:9,代码来源:test_repeated_edited_nearest_neighbours.py

示例5: test_renn_fit_sample

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,代码行数:12,代码来源:test_repeated_edited_nearest_neighbours.py

示例6: test_renn_fit

def test_renn_fit():
    """Test the fitting method"""

    # Create the object
    renn = RepeatedEditedNearestNeighbours(random_state=RND_SEED)
    # Fit the data
    renn.fit(X, Y)

    # Check if the data information have been computed
    assert_equal(renn.min_c_, 0)
    assert_equal(renn.maj_c_, 1)
    assert_equal(renn.stats_c_[0], 500)
    assert_equal(renn.stats_c_[1], 4500)
开发者ID:integrallyclosed,项目名称:imbalanced-learn,代码行数:13,代码来源:test_repeated_edited_nearest_neighbours.py

示例7: test_renn_fit_sample_with_indices

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,代码行数:15,代码来源:test_repeated_edited_nearest_neighbours.py

示例8: test_multiclass_fit_sample

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,代码行数:16,代码来源:test_repeated_edited_nearest_neighbours.py

示例9: train_decisiontree_with

def train_decisiontree_with(configurationname, train_data, k, score_function, undersam=False, oversam=False,
                            export=False):
    assert k > 0
    print("Training with configuration " + configurationname)
    X_train, y_train, id_to_a_train = train_data
    dtc = DecisionTreeClassifier(random_state=0)

    print("Feature Selection")
    # selector = SelectFpr(score_function)
    selector = SelectKBest(score_function, k=k)
    result = selector.fit(X_train, y_train)
    X_train = selector.transform(X_train)

    fitted_ids = [i for i in result.get_support(indices=True)]

    print("Apply Resampling")
    print(Counter(y_train))
    if undersam and not oversam:
        renn = RepeatedEditedNearestNeighbours()
        X_train, y_train = renn.fit_resample(X_train, y_train)
    if oversam and not undersam:
        # feature_indices_array = list(range(len(f_to_id)))
        # smote_nc = SMOTENC(categorical_features=feature_indices_array, random_state=0)
        # X_train, y_train = smote_nc.fit_resample(X_train, y_train)
        sm = SMOTE(random_state=42)
        X_train, y_train = sm.fit_resample(X_train, y_train)
    if oversam and undersam:
        smote_enn = SMOTEENN(random_state=0)
        X_train, y_train = smote_enn.fit_resample(X_train, y_train)
    print(Counter(y_train))

    print("Train Classifier")
    dtc = dtc.fit(X_train, y_train, check_input=True)

    if export:
        export_graphviz(dtc, out_file=DATAP + "/temp/trees/sltree_" + configurationname + ".dot", filled=True)
        transform(fitted_ids, configurationname)

    print("Self Accuracy: " + str(dtc.score(X_train, y_train)))

    return selector, dtc
开发者ID:softlang,项目名称:wikionto,代码行数:41,代码来源:decision_tree.py

示例10: EditedNearestNeighbours

enn = EditedNearestNeighbours()
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()
开发者ID:dvro,项目名称:imbalanced-learn,代码行数:31,代码来源:plot_allknn.py

示例11: test_renn_iter_wrong

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,代码行数:5,代码来源:test_repeated_edited_nearest_neighbours.py

示例12: test_deprecation_random_state

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,代码行数:5,代码来源:test_repeated_edited_nearest_neighbours.py

示例13: test_renn_not_good_object

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,代码行数:6,代码来源:test_repeated_edited_nearest_neighbours.py


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