当前位置: 首页>>代码示例>>Python>>正文


Python SMOTE.fit方法代码示例

本文整理汇总了Python中imblearn.over_sampling.SMOTE.fit方法的典型用法代码示例。如果您正苦于以下问题:Python SMOTE.fit方法的具体用法?Python SMOTE.fit怎么用?Python SMOTE.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imblearn.over_sampling.SMOTE的用法示例。


在下文中一共展示了SMOTE.fit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sample_svm

# 需要导入模块: from imblearn.over_sampling import SMOTE [as 别名]
# 或者: from imblearn.over_sampling.SMOTE import fit [as 别名]
def test_sample_svm():
    """Test sample function with SVM SMOTE."""

    # Create the object
    kind = 'svm'
    smote = SMOTE(random_state=RND_SEED, kind=kind)
    # Fit the data
    smote.fit(X, Y)

    X_resampled, y_resampled = smote.fit_sample(X, Y)

    X_gt = np.array([[0.11622591, -0.0317206], [0.77481731, 0.60935141],
                     [1.25192108, -0.22367336], [0.53366841, -0.30312976],
                     [1.52091956, -0.49283504], [-0.28162401, -2.10400981],
                     [0.83680821, 1.72827342], [0.3084254, 0.33299982],
                     [0.70472253, -0.73309052], [0.28893132, -0.38761769],
                     [1.15514042, 0.0129463], [0.88407872, 0.35454207],
                     [1.31301027, -0.92648734], [-1.11515198, -0.93689695],
                     [-0.18410027, -0.45194484], [0.9281014, 0.53085498],
                     [-0.14374509, 0.27370049], [-0.41635887, -0.38299653],
                     [0.08711622, 0.93259929], [1.70580611, -0.11219234],
                     [0.47436888, -0.2645749], [1.07844561, -0.19435291],
                     [1.44015515, -1.30621303]])
    y_gt = np.array(
        [0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0])
    assert_array_almost_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:29,代码来源:test_smote.py

示例2: test_sample_wrong_X

# 需要导入模块: from imblearn.over_sampling import SMOTE [as 别名]
# 或者: from imblearn.over_sampling.SMOTE import fit [as 别名]
def test_sample_wrong_X():
    """Test either if an error is raised when X is different at fitting
    and sampling"""

    # Create the object
    sm = SMOTE(random_state=RND_SEED)
    sm.fit(X, Y)
    assert_raises(RuntimeError, sm.sample,
                  np.random.random((100, 40)), np.array([0] * 50 + [1] * 50))
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:11,代码来源:test_smote.py

示例3: test_smote_fit

# 需要导入模块: from imblearn.over_sampling import SMOTE [as 别名]
# 或者: from imblearn.over_sampling.SMOTE import fit [as 别名]
def test_smote_fit():
    """Test the fitting method"""

    # Create the object
    smote = SMOTE(random_state=RND_SEED)
    # Fit the data
    smote.fit(X, Y)

    # Check if the data information have been computed
    assert_equal(smote.min_c_, 0)
    assert_equal(smote.maj_c_, 1)
    assert_equal(smote.stats_c_[0], 8)
    assert_equal(smote.stats_c_[1], 12)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:15,代码来源:test_smote.py

示例4: test_sample_regular

# 需要导入模块: from imblearn.over_sampling import SMOTE [as 别名]
# 或者: from imblearn.over_sampling.SMOTE import fit [as 别名]
def test_sample_regular():
    """Test sample function with regular SMOTE."""

    # Create the object
    kind = 'regular'
    smote = SMOTE(random_state=RND_SEED, kind=kind)
    # 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_reg_x.npy'))
    y_gt = np.load(os.path.join(currdir, 'data', 'smote_reg_y.npy'))
    assert_array_equal(X_resampled, X_gt)
    assert_array_equal(y_resampled, y_gt)
开发者ID:integrallyclosed,项目名称:imbalanced-learn,代码行数:18,代码来源:test_smote.py


注:本文中的imblearn.over_sampling.SMOTE.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。