本文整理汇总了Python中imblearn.under_sampling.InstanceHardnessThreshold类的典型用法代码示例。如果您正苦于以下问题:Python InstanceHardnessThreshold类的具体用法?Python InstanceHardnessThreshold怎么用?Python InstanceHardnessThreshold使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InstanceHardnessThreshold类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iht_fit_sample_with_indices
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)
示例2: test_iht_fit_sample_half
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)
示例3: test_iht_sample_wrong_X
def test_iht_sample_wrong_X():
"""Test either if an error is raised when X is different at fitting
and sampling"""
# Create the object
iht = InstanceHardnessThreshold(random_state=RND_SEED)
iht.fit(X, Y)
assert_raises(RuntimeError, iht.sample, np.random.random((100, 40)),
np.array([0] * 50 + [1] * 50))
示例4: test_iht_fit_sample
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)
示例5: test_iht_fit_sample_linear_svm
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)
示例6: test_iht_fit_sample_gradient_boosting
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)
示例7: test_iht_fit_sample_decision_tree
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)
示例8: test_iht_fit
def test_iht_fit():
"""Test the fitting method"""
# Create the object
iht = InstanceHardnessThreshold(ESTIMATOR, random_state=RND_SEED)
# Fit the data
iht.fit(X, Y)
# Check if the data information have been computed
assert_equal(iht.min_c_, 0)
assert_equal(iht.maj_c_, 1)
assert_equal(iht.stats_c_[0], 500)
assert_equal(iht.stats_c_[1], 4500)
示例9: test_iht_fit_resample
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)
示例10: test_iht_fit_sample_with_indices
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)
示例11: test_iht_fit_sample_class_obj
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)
示例12: test_iht_fit_sample_linear_svm
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)
示例13: test_iht_fit_sample_knn
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)
示例14: test_iht_fit_resample_wrong_class_obj
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)
示例15: PCA
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, 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.)