本文整理汇总了Python中imblearn.over_sampling.RandomOverSampler方法的典型用法代码示例。如果您正苦于以下问题:Python over_sampling.RandomOverSampler方法的具体用法?Python over_sampling.RandomOverSampler怎么用?Python over_sampling.RandomOverSampler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imblearn.over_sampling
的用法示例。
在下文中一共展示了over_sampling.RandomOverSampler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transform
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def transform(self, X, y=None):
# TODO how do we validate this happens before train/test split? Or do we need to? Can we implement it in the
# TODO simple trainer in the correct order and leave this to advanced users?
# Extract predicted column
y = np.squeeze(X[[self.predicted_column]])
# Copy the dataframe without the predicted column
temp_dataframe = X.drop([self.predicted_column], axis=1)
# Initialize and fit the under sampler
over_sampler = RandomOverSampler(random_state=self.random_seed)
x_over_sampled, y_over_sampled = over_sampler.fit_sample(temp_dataframe, y)
# Build the resulting under sampled dataframe
result = pd.DataFrame(x_over_sampled)
# Restore the column names
result.columns = temp_dataframe.columns
# Restore the y values
y_over_sampled = pd.Series(y_over_sampled)
result[self.predicted_column] = y_over_sampled
return result
示例2: create_sampler
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def create_sampler(sampler_name, random_state=None):
if sampler_name is None or sampler_name == 'None':
return None
if sampler_name.lower() == 'randomundersampler':
return RandomUnderSampler(random_state=random_state)
if sampler_name.lower() == 'tomeklinks':
return TomekLinks(random_state=random_state)
if sampler_name.lower() == 'enn':
return EditedNearestNeighbours(random_state=random_state)
if sampler_name.lower() == 'ncl':
return NeighbourhoodCleaningRule(random_state=random_state)
if sampler_name.lower() == 'randomoversampler':
return RandomOverSampler(random_state=random_state)
if sampler_name.lower() == 'smote':
return SMOTE(random_state=random_state)
if sampler_name.lower() == 'smotetomek':
return SMOTETomek(random_state=random_state)
if sampler_name.lower() == 'smoteenn':
return SMOTEENN(random_state=random_state)
else:
raise ValueError('Unsupported value \'%s\' for sampler' % sampler_name)
示例3: test_random_oversampling_limit_case
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def test_random_oversampling_limit_case(plot=False):
"""Execute k-means SMOTE with parameters equivalent to random oversampling"""
kmeans_smote = KMeansSMOTE(
random_state=RND_SEED,
imbalance_ratio_threshold=float('Inf'),
kmeans_args={
'n_clusters': 1
},
smote_args={
'k_neighbors': 0
}
)
random_oversampler = RandomOverSampler(random_state=RND_SEED)
X_resampled, y_resampled = kmeans_smote.fit_sample(X, Y)
X_resampled_random_oversampler, y_resampled_random_oversampler = random_oversampler.fit_sample(
X, Y)
if plot:
plot_resampled(X, X_resampled, Y, y_resampled,
'random_oversampling_limit_case_test_kmeans_smote')
plot_resampled(X, X_resampled_random_oversampler, Y, y_resampled_random_oversampler,
'random_oversampling_limit_case_test_random_oversampling')
assert_array_equal(X_resampled, X_resampled_random_oversampler)
assert_array_equal(y_resampled, y_resampled_random_oversampler)
示例4: __init__
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def __init__(self):
super(UpSampling, self).__init__(RandomOverSampler(random_state=RANDOM_SEED[BALANCE_UP_SAMPLING]),
BALANCE_UP_SAMPLING)
示例5: __init__
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def __init__(self, operator = None, sampling_strategy='auto', random_state=None):
if operator is None:
raise ValueError("Operator is a required argument.")
self._hyperparams = {
'sampling_strategy': sampling_strategy,
'random_state': random_state}
resampler_instance = OrigModel(**self._hyperparams)
super(RandomOverSamplerImpl, self).__init__(
operator = operator,
resampler = resampler_instance)
示例6: over_sample_random
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def over_sample_random(train_inputs, train_targets):
sampler = RandomOverSampler(random_state=32)
train_inputs, train_targets = _sampler_helper(sampler, train_inputs, train_targets)
return train_inputs, train_targets
示例7: test_objectmapper_oversampling
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def test_objectmapper_oversampling(self):
import imblearn.over_sampling as os
df = pdml.ModelFrame([])
self.assertIs(df.imbalance.over_sampling.ADASYN,
os.ADASYN)
self.assertIs(df.imbalance.over_sampling.RandomOverSampler,
os.RandomOverSampler)
self.assertIs(df.imbalance.over_sampling.SMOTE,
os.SMOTE)
示例8: resample
# 需要导入模块: from imblearn import over_sampling [as 别名]
# 或者: from imblearn.over_sampling import RandomOverSampler [as 别名]
def resample(self, X, y, target_size_strategy, seed):
from imblearn.over_sampling import RandomOverSampler as imblearn_RandomOverSampler
resampler = imblearn_RandomOverSampler(sampling_strategy=target_size_strategy, random_state=seed)
return resampler.fit_resample(X, y)