本文整理汇总了Python中imblearn.combine.SMOTEENN.fit_sample方法的典型用法代码示例。如果您正苦于以下问题:Python SMOTEENN.fit_sample方法的具体用法?Python SMOTEENN.fit_sample怎么用?Python SMOTEENN.fit_sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imblearn.combine.SMOTEENN
的用法示例。
在下文中一共展示了SMOTEENN.fit_sample方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error_wrong_object
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def test_error_wrong_object():
smote = 'rnd'
enn = 'rnd'
smt = SMOTEENN(smote=smote, random_state=RND_SEED)
with raises(ValueError, match="smote needs to be a SMOTE"):
smt.fit_sample(X, Y)
smt = SMOTEENN(enn=enn, random_state=RND_SEED)
with raises(ValueError, match="enn needs to be an "):
smt.fit_sample(X, Y)
示例2: test_sample_regular_half
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def test_sample_regular_half():
ratio = {0: 10, 1: 12}
smote = SMOTEENN(ratio=ratio, random_state=RND_SEED)
X_resampled, y_resampled = smote.fit_sample(X, Y)
X_gt = np.array([[1.52091956, -0.49283504],
[-0.28162401, -2.10400981],
[0.83680821, 1.72827342],
[0.08711622, 0.93259929]])
y_gt = np.array([0, 1, 1, 1])
assert_allclose(X_resampled, X_gt)
assert_array_equal(y_resampled, y_gt)
示例3: test_validate_estimator_default
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def test_validate_estimator_default():
smt = SMOTEENN(random_state=RND_SEED)
X_resampled, y_resampled = smt.fit_sample(X, Y)
X_gt = np.array([[1.52091956, -0.49283504],
[0.84976473, -0.15570176],
[0.61319159, -0.11571667],
[0.66052536, -0.28246518],
[-0.28162401, -2.10400981],
[0.83680821, 1.72827342],
[0.08711622, 0.93259929]])
y_gt = np.array([0, 0, 0, 0, 1, 1, 1])
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
assert_array_equal(y_resampled, y_gt)
示例4: test_sample_regular
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def test_sample_regular():
"""Test sample function with regular SMOTE."""
# Create the object
smote = SMOTEENN(random_state=RND_SEED)
# Fit the data
smote.fit(X, Y)
X_resampled, y_resampled = smote.fit_sample(X, Y)
currdir = os.path.dirname(os.path.abspath(__file__))
X_gt = np.load(os.path.join(currdir, 'data', 'smote_enn_reg_x.npy'))
y_gt = np.load(os.path.join(currdir, 'data', 'smote_enn_reg_y.npy'))
assert_array_equal(X_resampled, X_gt)
assert_array_equal(y_resampled, y_gt)
示例5: SMOTE
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def SMOTE(self, bug_rate, X, Y):
"""
Combine over- and under-sampling using SMOTE and
Edited Nearest Neighbours.
通过改进的SMOTE来对原来的数据集做处理
:param bug_rate:
:param X:数据集除了lable以外的部分
:param Y:lable信息
:return:处理过的X,Y。
"""
from collections import Counter
from imblearn.combine import SMOTEENN
sme = SMOTEENN(ratio=bug_rate)
x_res, y_res = sme.fit_sample(X, Y)
import numpy as np
nx = np.column_stack((x_res, y_res))
self.new_list_SMOTE = nx
示例6: test_sample_regular_pass_smote_enn
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
def test_sample_regular_pass_smote_enn():
smote = SMOTEENN(smote=SMOTE(ratio='auto', random_state=RND_SEED),
enn=EditedNearestNeighbours(ratio='all',
random_state=RND_SEED),
random_state=RND_SEED)
X_resampled, y_resampled = smote.fit_sample(X, Y)
X_gt = np.array([[1.52091956, -0.49283504],
[0.84976473, -0.15570176],
[0.61319159, -0.11571667],
[0.66052536, -0.28246518],
[-0.28162401, -2.10400981],
[0.83680821, 1.72827342],
[0.08711622, 0.93259929]])
y_gt = np.array([0, 0, 0, 0, 1, 1, 1])
assert_allclose(X_resampled, X_gt, rtol=R_TOL)
assert_array_equal(y_resampled, y_gt)
示例7: __init__
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
class Undersampler:
def __init__(self,kind,data,target,verbose = False, ratio = 'auto'):
assert len(data) == len(target)
self.data = data
self.target = target
if kind in [Undersampling.ClusterCentroids]:
if verbose: print('> CLUSTER CENTROIDS')
# Undersampling por Cluster Centroids
self.undersampler = ClusterCentroids(verbose = verbose, ratio=ratio)
elif kind in [Undersampling.SMOTEENN]:
if verbose: print('> SMOTEENN')
# Undersampling por SMOTEENN
self.undersampler = SMOTEENN(verbose = verbose, ratio=ratio)
else:
raise("Nonexistent undersampling type: "+kind.name)
def balance(self):
#return self.undersampler.fit_transform(self.data, self.target)
return self.undersampler.fit_sample(self.data, self.target)
示例8: return
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
return (data[i - 1] + data[i])/2
start = time()
n_iter = 100 ## Number of evaluations (SMAC)
n_validations = 7 ## Number of Monte-Carlo Cross-Validations for each model's accuracy evaluated
## Dataset 11
url11 = "https://archive.ics.uci.edu/ml/machine-learning-databases/tic-mld/ticdata2000.txt"
dataset11 = np.genfromtxt(urllib.urlopen(url11))
X = dataset11[:,0:85]
Y = dataset11[:,85]
sm = SMOTEENN()
X, Y = sm.fit_sample(X, Y)
# We fit the MLP with the hyperparameters given and return the model's median accuracy from 7 trials
def mlp(number_layers, number_neurons_1, number_neurons_2, number_neurons_3, number_neurons_4, dropout_rate):
layers = []
number_neurons = []
number_neurons.append(number_neurons_1)
number_neurons.append(number_neurons_2)
number_neurons.append(number_neurons_3)
number_neurons.append(number_neurons_4)
for i in np.arange(number_layers):
layers.append(Layer("Sigmoid", units=number_neurons[i], dropout = dropout_rate))
示例9: train_test_split
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
plt.text(j, i, cm[i, j],
horizontalalignment="center",
color="white" if cm[i, j] > thresh else "black")
plt.tight_layout()
plt.ylabel('True label')
plt.xlabel('Predicted label')
#define X y
X, y = data.loc[:,data.columns != 'state'].values, data.loc[:,data.columns == 'state'].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
#smoteen
sme = SMOTEENN(random_state=42)
os_X,os_y = sme.fit_sample(X_train,y_train)
#QDA
clf_QDA = QuadraticDiscriminantAnalysis(store_covariances=True)
clf_QDA.fit(os_X, os_y)
y_true, y_pred = y_test, clf_QDA.predict(X_test)
#F1_score, precision, recall, specifity, G score
print "F1_score : %.4g" % metrics.f1_score(y_true, y_pred)
print "Recall : %.4g" % metrics.recall_score(y_true, y_pred)
recall = metrics.recall_score(y_true, y_pred)
print "Precision : %.4g" % metrics.precision_score(y_true, y_pred)
#Compute confusion matrix
cnf_matrix = confusion_matrix(y_test,y_pred)
np.set_printoptions(precision=2)
示例10: make_classification
# 需要导入模块: from imblearn.combine import SMOTEENN [as 别名]
# 或者: from imblearn.combine.SMOTEENN import fit_sample [as 别名]
from imblearn.combine import SMOTEENN
# 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=5000, 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 + ENN
sm = SMOTEENN()
X_resampled, y_resampled = sm.fit_sample(X, y)
X_res_vis = pca.transform(X_resampled)
# Two subplots, unpack the axes array immediately
f, (ax1, ax2) = plt.subplots(1, 2)
ax1.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)
ax1.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)
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=.5, edgecolor=almost_black,
facecolor=palette[0], linewidth=0.15)
ax2.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],