當前位置: 首頁>>代碼示例>>Python>>正文


Python combine.SMOTEENN屬性代碼示例

本文整理匯總了Python中imblearn.combine.SMOTEENN屬性的典型用法代碼示例。如果您正苦於以下問題:Python combine.SMOTEENN屬性的具體用法?Python combine.SMOTEENN怎麽用?Python combine.SMOTEENN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在imblearn.combine的用法示例。


在下文中一共展示了combine.SMOTEENN屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_sampler

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [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) 
開發者ID:melqkiades,項目名稱:yelp,代碼行數:24,代碼來源:sampler_factory.py

示例2: __init__

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [as 別名]
def __init__(self, operator = None, sampling_strategy='auto', random_state=None, smote=None, enn=None):
        if operator is None:
            raise ValueError("Operator is a required argument.")

        self._hyperparams = {
            'sampling_strategy': sampling_strategy,
            'random_state': random_state,
            'smote': smote,
            'enn': enn}
    
        resampler_instance = OrigModel(**self._hyperparams)
        super(SMOTEENNImpl, self).__init__(
            operator = operator,
            resampler = resampler_instance) 
開發者ID:IBM,項目名稱:lale,代碼行數:16,代碼來源:smoteenn.py

示例3: resample_smote_enn

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [as 別名]
def resample_smote_enn(train_inputs, train_targets):
    sampler = SMOTEENN(random_state=32)
    train_inputs, train_targets = _sampler_helper(sampler, train_inputs, train_targets)
    return train_inputs, train_targets 
開發者ID:HunterMcGushion,項目名稱:hyperparameter_hunter,代碼行數:6,代碼來源:imblearn_resampling_example.py

示例4: test_objectmapper_combine

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [as 別名]
def test_objectmapper_combine(self):
        import imblearn.combine as combine
        df = pdml.ModelFrame([])
        self.assertIs(df.imbalance.combine.SMOTEENN,
                      combine.SMOTEENN)
        self.assertIs(df.imbalance.combine.SMOTETomek,
                      combine.SMOTETomek) 
開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:9,代碼來源:test_imbalance.py

示例5: test_sample

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [as 別名]
def test_sample(self):
        from imblearn.under_sampling import ClusterCentroids, OneSidedSelection
        from imblearn.over_sampling import ADASYN, SMOTE
        from imblearn.combine import SMOTEENN, SMOTETomek

        models = [ClusterCentroids, OneSidedSelection, ADASYN, SMOTE,
                  SMOTEENN, SMOTETomek]

        X = np.random.randn(100, 5)
        y = np.array([0, 1]).repeat([80, 20])

        df = pdml.ModelFrame(X, target=y, columns=list('ABCDE'))

        for model in models:
            mod1 = model(random_state=self.random_state)
            mod2 = model(random_state=self.random_state)

            df.fit(mod1)
            mod2.fit(X, y)

            result = df.fit_resample(mod1)
            expected_X, expected_y = mod2.fit_resample(X, y)

            self.assertIsInstance(result, pdml.ModelFrame)
            tm.assert_numpy_array_equal(result.target.values, expected_y)
            tm.assert_numpy_array_equal(result.data.values, expected_X)
            tm.assert_index_equal(result.columns, df.columns)

            mod1 = model(random_state=self.random_state)
            mod2 = model(random_state=self.random_state)

            result = df.fit_sample(mod1)
            expected_X, expected_y = mod2.fit_sample(X, y)

            self.assertIsInstance(result, pdml.ModelFrame)
            tm.assert_numpy_array_equal(result.target.values, expected_y)
            tm.assert_numpy_array_equal(result.data.values, expected_X)
            tm.assert_index_equal(result.columns, df.columns) 
開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:40,代碼來源:test_imbalance.py

示例6: perform_oversampling

# 需要導入模塊: from imblearn import combine [as 別名]
# 或者: from imblearn.combine import SMOTEENN [as 別名]
def perform_oversampling(oversamp_method, db_path, oversamp_features_name, tr_features, tr_labels):
    start = time.time()
    
    oversamp_features_pickle_name = db_path + oversamp_features_name + '_' + oversamp_method + '.p'
    print(oversamp_features_pickle_name)

    if True:
        print("Oversampling method:\t" + oversamp_method + " ...")
        # 1 SMOTE
        if oversamp_method == 'SMOTE':  
            #kind={'borderline1', 'borderline2', 'svm'}
            svm_model = svm.SVC(C=0.001, kernel='rbf', degree=3, gamma='auto', decision_function_shape='ovo')
            oversamp = SMOTE(ratio='auto', random_state=None, k_neighbors=5, m_neighbors=10, out_step=0.5, kind='svm', svm_estimator=svm_model, n_jobs=1)

            # PROBAR SMOTE CON OTRO KIND

        elif oversamp_method == 'SMOTE_regular_min':
            oversamp = SMOTE(ratio='minority', random_state=None, k_neighbors=5, m_neighbors=10, out_step=0.5, kind='regular', svm_estimator=None, n_jobs=1)

        elif oversamp_method == 'SMOTE_regular':
            oversamp = SMOTE(ratio='auto', random_state=None, k_neighbors=5, m_neighbors=10, out_step=0.5, kind='regular', svm_estimator=None, n_jobs=1)
  
        elif oversamp_method == 'SMOTE_border':
            oversamp = SMOTE(ratio='auto', random_state=None, k_neighbors=5, m_neighbors=10, out_step=0.5, kind='borderline1', svm_estimator=None, n_jobs=1)
                 
        # 2 SMOTEENN
        elif oversamp_method == 'SMOTEENN':    
            oversamp = SMOTEENN()

        # 3 SMOTE TOMEK
        # NOTE: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.3904&rep=rep1&type=pdf
        elif oversamp_method == 'SMOTETomek':
            oversamp = SMOTETomek()

        # 4 ADASYN
        elif oversamp_method == 'ADASYN':
            oversamp = ADASYN(ratio='auto', random_state=None, k=None, n_neighbors=5, n_jobs=cpu_threads)
 
        tr_features_balanced, tr_labels_balanced  = oversamp.fit_sample(tr_features, tr_labels)
        # TODO Write data oversampled!
        print("Writing oversampled data at: " + oversamp_features_pickle_name + " ...")
        np.savetxt('mit_db/' + oversamp_features_name + '_DS1_labels.csv', tr_labels_balanced.astype(int), '%.0f') 
        f = open(oversamp_features_pickle_name, 'wb')
        pickle.dump(tr_features_balanced, f, 2)
        f.close

    end = time.time()

    count = collections.Counter(tr_labels_balanced)
    print("Oversampling balance")
    print(count)
    print("Time required: " + str(format(end - start, '.2f')) + " sec" )

    return tr_features_balanced, tr_labels_balanced 
開發者ID:mondejar,項目名稱:ecg-classification,代碼行數:56,代碼來源:oversampling.py


注:本文中的imblearn.combine.SMOTEENN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。