本文整理汇总了Python中imblearn.combine.SMOTETomek.fit_resample方法的典型用法代码示例。如果您正苦于以下问题:Python SMOTETomek.fit_resample方法的具体用法?Python SMOTETomek.fit_resample怎么用?Python SMOTETomek.fit_resample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imblearn.combine.SMOTETomek
的用法示例。
在下文中一共展示了SMOTETomek.fit_resample方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error_wrong_object
# 需要导入模块: from imblearn.combine import SMOTETomek [as 别名]
# 或者: from imblearn.combine.SMOTETomek import fit_resample [as 别名]
def test_error_wrong_object():
smote = 'rnd'
tomek = 'rnd'
smt = SMOTETomek(smote=smote, random_state=RND_SEED)
with raises(ValueError, match="smote needs to be a SMOTE"):
smt.fit_resample(X, Y)
smt = SMOTETomek(tomek=tomek, random_state=RND_SEED)
with raises(ValueError, match="tomek needs to be a TomekLinks"):
smt.fit_resample(X, Y)
示例2: test_validate_estimator_default
# 需要导入模块: from imblearn.combine import SMOTETomek [as 别名]
# 或者: from imblearn.combine.SMOTETomek import fit_resample [as 别名]
def test_validate_estimator_default():
smt = SMOTETomek(random_state=RND_SEED)
X_resampled, y_resampled = smt.fit_resample(X, Y)
X_gt = np.array([[0.68481731, 0.51935141], [1.34192108, -0.13367336], [
0.62366841, -0.21312976
], [1.61091956, -0.40283504], [-0.37162401,
-2.19400981], [0.74680821, 1.63827342],
[0.61472253, -0.82309052], [0.19893132, -0.47761769],
[1.40301027, -0.83648734], [-1.20515198, -1.02689695], [
-0.23374509, 0.18370049
], [-0.00288378, 0.84259929], [1.79580611, -0.02219234], [
0.38307743, -0.05670439
], [0.70319159, -0.02571667], [0.75052536, -0.19246518]])
y_gt = np.array([1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0])
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
assert_array_equal(y_resampled, y_gt)
示例3: test_sample_regular_half
# 需要导入模块: from imblearn.combine import SMOTETomek [as 别名]
# 或者: from imblearn.combine.SMOTETomek import fit_resample [as 别名]
def test_sample_regular_half():
sampling_strategy = {0: 9, 1: 12}
smote = SMOTETomek(
sampling_strategy=sampling_strategy, random_state=RND_SEED)
X_resampled, y_resampled = smote.fit_resample(X, Y)
X_gt = np.array([[0.68481731, 0.51935141], [0.62366841, -0.21312976], [
1.61091956, -0.40283504
], [-0.37162401, -2.19400981], [0.74680821,
1.63827342], [0.61472253, -0.82309052],
[0.19893132, -0.47761769], [1.40301027, -0.83648734],
[-1.20515198, -1.02689695], [-0.23374509, 0.18370049], [
-0.00288378, 0.84259929
], [1.79580611, -0.02219234], [0.45784496, -0.1053161]])
y_gt = np.array([1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0])
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
assert_array_equal(y_resampled, y_gt)
示例4: test_error_wrong_object
# 需要导入模块: from imblearn.combine import SMOTETomek [as 别名]
# 或者: from imblearn.combine.SMOTETomek import fit_resample [as 别名]
def test_error_wrong_object(smote_params, err_msg):
smt = SMOTETomek(**smote_params)
with pytest.raises(ValueError, match=err_msg):
smt.fit_resample(X, Y)
示例5: print
# 需要导入模块: from imblearn.combine import SMOTETomek [as 别名]
# 或者: from imblearn.combine.SMOTETomek import fit_resample [as 别名]
print(__doc__)
# Generate the dataset
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
n_informative=3, n_redundant=1, flip_y=0,
n_features=20, n_clusters_per_class=1,
n_samples=100, random_state=10)
# Instanciate a PCA object for the sake of easy visualisation
pca = PCA(n_components=2)
# Fit and transform x to visualise inside a 2D feature space
X_vis = pca.fit_transform(X)
# Apply SMOTE + Tomek links
sm = SMOTETomek()
X_resampled, y_resampled = sm.fit_resample(X, y)
X_res_vis = pca.transform(X_resampled)
# Two subplots, unpack the axes array immediately
f, (ax1, ax2) = plt.subplots(1, 2)
c0 = ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0",
alpha=0.5)
c1 = ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1",
alpha=0.5)
ax1.set_title('Original set')
ax2.scatter(X_res_vis[y_resampled == 0, 0], X_res_vis[y_resampled == 0, 1],
label="Class #0", alpha=0.5)
ax2.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],
label="Class #1", alpha=0.5)