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


Python InstanceHardnessThreshold.fit_sample方法代码示例

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


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

示例1: test_iht_fit_sample_half

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
def test_iht_fit_sample_half():
    """Test the fit sample routine with a 0.5 ratio"""

    # Resample the data
    ratio = 0.7
    iht = InstanceHardnessThreshold(ESTIMATOR, ratio=ratio,
                                    random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251],
                     [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941],
                     [0.91542919, -0.65453327],
                     [-0.03852113, 0.40910479],
                     [-0.43877303, 1.07366684],
                     [-0.85795321, 0.82980738],
                     [-0.18430329, 0.52328473],
                     [-0.30126957, -0.66268378],
                     [-0.65571327, 0.42412021],
                     [-0.28305528, 0.30284991],
                     [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502],
                     [-0.00717161, 0.00318087]])
    y_gt = np.array([0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:dvro,项目名称:imbalanced-learn,代码行数:28,代码来源:test_instance_hardness_threshold.py

示例2: test_iht_fit_sample_with_indices

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

    # Resample the data
    iht = InstanceHardnessThreshold(ESTIMATOR, return_indices=True,
                                    random_state=RND_SEED)
    X_resampled, y_resampled, idx_under = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251],
                     [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941],
                     [0.91542919, -0.65453327],
                     [-0.43877303, 1.07366684],
                     [-0.85795321, 0.82980738],
                     [-0.18430329, 0.52328473],
                     [-0.65571327, 0.42412021],
                     [-0.28305528, 0.30284991],
                     [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502],
                     [-0.00717161, 0.00318087]])
    y_gt = np.array([0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0])
    idx_gt = np.array([0, 1, 2, 3, 5, 6, 7, 9, 10, 12, 13, 14])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
    assert_array_equal(idx_under, idx_gt)
开发者ID:dvro,项目名称:imbalanced-learn,代码行数:27,代码来源:test_instance_hardness_threshold.py

示例3: test_iht_fit_sample

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

    # Resample the data
    iht = InstanceHardnessThreshold(ESTIMATOR, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

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

示例4: test_iht_fit_sample_linear_svm

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

    # Resample the data
    est = 'linear-svm'
    iht = InstanceHardnessThreshold(est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

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

示例5: test_iht_fit_sample_gradient_boosting

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

    # Resample the data
    est = 'gradient-boosting'
    iht = InstanceHardnessThreshold(est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

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

示例6: test_iht_fit_sample_decision_tree

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
def test_iht_fit_sample_decision_tree():
    """Test the fit sample routine with decision-tree"""

    # Resample the data
    est = 'decision-tree'
    iht = InstanceHardnessThreshold(est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

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

示例7: test_iht_fit_sample_with_indices

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

    # Resample the data
    iht = InstanceHardnessThreshold(ESTIMATOR, return_indices=True,
                                    random_state=RND_SEED)
    X_resampled, y_resampled, idx_under = iht.fit_sample(X, Y)

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

示例8: test_iht_fit_sample_class_obj

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
def test_iht_fit_sample_class_obj():
    """Test the fit sample routine passing a classifiermixin object"""

    # Resample the data
    est = GradientBoostingClassifier(random_state=RND_SEED)
    iht = InstanceHardnessThreshold(estimator=est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251], [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941], [0.91542919, -0.65453327],
                     [-0.43877303, 1.07366684], [-0.85795321, 0.82980738],
                     [-0.18430329, 0.52328473], [-0.65571327, 0.42412021],
                     [-0.28305528, 0.30284991], [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502], [-0.00717161, 0.00318087]])
    y_gt = np.array([0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:19,代码来源:test_instance_hardness_threshold.py

示例9: test_iht_fit_sample_linear_svm

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

    # Resample the data
    est = 'linear-svm'
    iht = InstanceHardnessThreshold(est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251], [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941], [0.91542919, -0.65453327],
                     [-0.03852113, 0.40910479], [-0.43877303, 1.07366684],
                     [-0.18430329, 0.52328473], [-0.65571327, 0.42412021],
                     [-0.28305528, 0.30284991], [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502], [-0.00717161, 0.00318087]])
    y_gt = np.array([0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:19,代码来源:test_instance_hardness_threshold.py

示例10: test_iht_fit_sample_knn

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

    # Resample the data
    est = 'knn'
    iht = InstanceHardnessThreshold(est, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251], [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941], [0.91542919, -0.65453327],
                     [-0.43877303, 1.07366684], [-0.85795321, 0.82980738],
                     [-0.30126957, -0.66268378], [-0.65571327, 0.42412021],
                     [0.20246714, -0.34727125], [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502], [-0.00717161, 0.00318087]])
    y_gt = np.array([0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:19,代码来源:test_instance_hardness_threshold.py

示例11: test_iht_fit_sample

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
def test_iht_fit_sample():
    iht = InstanceHardnessThreshold(ESTIMATOR, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_sample(X, Y)

    X_gt = np.array([[-0.3879569, 0.6894251],
                     [0.91542919, -0.65453327],
                     [-0.65571327, 0.42412021],
                     [1.06446472, -1.09279772],
                     [0.30543283, -0.02589502],
                     [-0.00717161, 0.00318087],
                     [-0.09322739, 1.28177189],
                     [-0.77740357, 0.74097941],
                     [-0.43877303, 1.07366684],
                     [-0.85795321, 0.82980738],
                     [-0.18430329, 0.52328473],
                     [-0.28305528, 0.30284991]])
    y_gt = np.array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1])
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:21,代码来源:test_instance_hardness_threshold.py

示例12: PCA

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
pca = PCA(n_components=2)
X_vis = pca.fit_transform(X)

# Two subplots, unpack the axes array immediately
f, axs = plt.subplots(2, 2)

axs = [a for ax in axs for a in ax]
for ax, ratio in zip(axs, [0.0, 0.1, 0.3, 0.5]):
    if ratio == 0.0:
        ax.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0",
                    alpha=0.5, edgecolor=almost_black, facecolor=palette[0],
                    linewidth=0.15)
        ax.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1",
                   alpha=0.5, edgecolor=almost_black, facecolor=palette[2],
                   linewidth=0.15)
        ax.set_title('Original set')
    else:
        iht = InstanceHardnessThreshold(ratio=ratio)
        X_res, y_res = iht.fit_sample(X, y)
        X_res_vis = pca.transform(X_res)

        ax.scatter(X_res_vis[y_res == 0, 0], X_res_vis[y_res == 0, 1],
                   label="Class #0", alpha=.5, edgecolor=almost_black,
                   facecolor=palette[0], linewidth=0.15)
        ax.scatter(X_res_vis[y_res == 1, 0], X_res_vis[y_res == 1, 1],
                   label="Class #1", alpha=.5, edgecolor=almost_black,
                   facecolor=palette[2], linewidth=0.15)
        ax.set_title('Instance Hardness Threshold ({})'.format(ratio))

plt.show()
开发者ID:apyeh,项目名称:UnbalancedDataset,代码行数:32,代码来源:plot_instance_hardness_threshold.py

示例13: test_iht_fit_sample_wrong_class_obj

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_sample [as 别名]
def test_iht_fit_sample_wrong_class_obj():
    from sklearn.cluster import KMeans
    est = KMeans()
    iht = InstanceHardnessThreshold(estimator=est, random_state=RND_SEED)
    with raises(ValueError, match="Invalid parameter `estimator`"):
        iht.fit_sample(X, Y)
开发者ID:glemaitre,项目名称:imbalanced-learn,代码行数:8,代码来源:test_instance_hardness_threshold.py


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