本文整理汇总了Python中imblearn.under_sampling.RepeatedEditedNearestNeighbours.fit_resample方法的典型用法代码示例。如果您正苦于以下问题:Python RepeatedEditedNearestNeighbours.fit_resample方法的具体用法?Python RepeatedEditedNearestNeighbours.fit_resample怎么用?Python RepeatedEditedNearestNeighbours.fit_resample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imblearn.under_sampling.RepeatedEditedNearestNeighbours
的用法示例。
在下文中一共展示了RepeatedEditedNearestNeighbours.fit_resample方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_renn_fit_resample_with_indices
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
def test_renn_fit_resample_with_indices():
renn = RepeatedEditedNearestNeighbours(return_indices=True)
X_resampled, y_resampled, idx_under = 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
])
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)
示例2: test_renn_fit_resample_mode
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
def test_renn_fit_resample_mode():
nn = NearestNeighbors(n_neighbors=4)
renn = RepeatedEditedNearestNeighbours(n_neighbors=nn, kind_sel='mode')
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], [-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)
示例3: train_decisiontree_with
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
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
示例4: test_renn_iter_wrong
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
def test_renn_iter_wrong():
max_iter = -1
renn = RepeatedEditedNearestNeighbours(max_iter=max_iter)
with pytest.raises(ValueError):
renn.fit_resample(X, Y)
示例5: test_deprecation_random_state
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
def test_deprecation_random_state():
renn = RepeatedEditedNearestNeighbours(random_state=0)
with warns(
DeprecationWarning, match="'random_state' is deprecated from 0.4"):
renn.fit_resample(X, Y)
示例6: test_renn_not_good_object
# 需要导入模块: from imblearn.under_sampling import RepeatedEditedNearestNeighbours [as 别名]
# 或者: from imblearn.under_sampling.RepeatedEditedNearestNeighbours import fit_resample [as 别名]
def test_renn_not_good_object():
nn = 'rnd'
renn = RepeatedEditedNearestNeighbours(n_neighbors=nn, kind_sel='mode')
with pytest.raises(ValueError):
renn.fit_resample(X, Y)