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


Python InstanceHardnessThreshold.fit_resample方法代码示例

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


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

示例1: test_iht_fit_resample

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_resample [as 别名]
def test_iht_fit_resample():
    iht = InstanceHardnessThreshold(ESTIMATOR, random_state=RND_SEED)
    X_resampled, y_resampled = iht.fit_resample(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:bodycat,项目名称:imbalanced-learn,代码行数:16,代码来源:test_instance_hardness_threshold.py

示例2: test_iht_fit_resample_wrong_class_obj

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_resample [as 别名]
def test_iht_fit_resample_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_resample(X, Y)
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:8,代码来源:test_instance_hardness_threshold.py

示例3: zip

# 需要导入模块: from imblearn.under_sampling import InstanceHardnessThreshold [as 别名]
# 或者: from imblearn.under_sampling.InstanceHardnessThreshold import fit_resample [as 别名]
# 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, sampling_strategy in zip(axs, (0,
                                       {1: 25, 0: 10},
                                       {1: 14, 0: 10},
                                       {1: 10, 0: 10})):
    if sampling_strategy == 0:
        c0, c1 = plot_resampling(ax, X_vis, y, 'Original set')
    else:
        iht = InstanceHardnessThreshold(sampling_strategy=sampling_strategy,
                                        estimator=LogisticRegression(),
                                        return_indices=True)
        X_res, y_res, idx_res = iht.fit_resample(X, y)
        X_res_vis = pca.transform(X_res)
        plot_resampling(ax, X_res_vis, y_res,
                        'Instance Hardness Threshold ({})'
                        .format(sampling_strategy))
        # plot samples which have been removed
        idx_samples_removed = np.setdiff1d(np.arange(X_vis.shape[0]),
                                           idx_res)
        c3 = ax.scatter(X_vis[idx_samples_removed, 0],
                        X_vis[idx_samples_removed, 1],
                        alpha=.2, label='Removed samples')

plt.figlegend((c0, c1, c3), ('Class #0', 'Class #1', 'Removed samples'),
              loc='lower center', ncol=3, labelspacing=0.)
plt.tight_layout(pad=3)
plt.show()
开发者ID:bodycat,项目名称:imbalanced-learn,代码行数:32,代码来源:plot_instance_hardness_threshold.py


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