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


Python dummy.DummyClassifier方法代码示例

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


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

示例1: measure_performance_dummy_classifier

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def measure_performance_dummy_classifier():
    outfile = get_out_file("dummy_classifier")
    write_result(outfile, "smell,auc,precision,recall,f1,average_precision\n")
    for smell in smell_list:
        data_path = os.path.join(os.path.join(TOKENIZER_OUT_PATH, smell), DIM)
        input_data = get_all_data(data_path, smell)
        # clf = DummyClassifier(strategy='stratified', random_state=0)
        clf = DummyClassifier(strategy='most_frequent', random_state=0)
        inverted_train_labels = inputs.invert_labels(input_data.train_labels)

        # clf.fit(input_data.train_data, input_data.train_labels)
        clf.fit(input_data.train_data, inverted_train_labels)
        y_pred = clf.predict(input_data.eval_data)

        auc, precision, recall, f1, average_precision, fpr, tpr = \
            metrics_util.get_all_metrics_(input_data.eval_labels, y_pred)

        write_result(outfile,
                     smell + "," + str(auc) + "," + str(precision) + "," + str(recall) + "," + str(f1) + "," + str(
                         average_precision) + "\n") 
开发者ID:tushartushar,项目名称:DeepLearningSmells,代码行数:22,代码来源:rq1_rnn_emb_lstm.py

示例2: measure_performance_dummy_classifier

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def measure_performance_dummy_classifier():
    outfile = get_out_file("dummy_classifier")
    write_result(outfile, "smell,auc,precision,recall,f1,average_precision\n")
    for smell in smell_list:
        data_path = os.path.join(os.path.join(TOKENIZER_OUT_PATH, smell), DIM)
        input_data = get_all_data(data_path, smell)
        # clf = DummyClassifier(strategy='stratified', random_state=0)
        clf = DummyClassifier(strategy='most_frequent', random_state=0)
        inverted_train_labels = inputs.invert_labels(input_data.train_labels)

        clf.fit(input_data.train_data, inverted_train_labels)
        # clf.fit(input_data.train_data, input_data.train_labels)
        y_pred = clf.predict(input_data.eval_data)


        auc, precision, recall, f1, average_precision, fpr, tpr = \
            metrics_util.get_all_metrics_(input_data.eval_labels, y_pred)

        write_result(outfile, smell +"," + str(auc) +"," + str(precision) +"," + str(recall) +"," + str(f1) +"," + str(average_precision) + "\n") 
开发者ID:tushartushar,项目名称:DeepLearningSmells,代码行数:21,代码来源:rq1_cnn_2d.py

示例3: measure_performance_dummy_classifier

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def measure_performance_dummy_classifier():
    outfile = get_out_file("dummy_classifier")
    write_result(outfile, "smell,auc,precision,recall,f1,average_precision\n")
    for smell in smell_list:
        data_path = os.path.join(os.path.join(TOKENIZER_OUT_PATH, smell), DIM)
        input_data = get_all_data(data_path, smell)
        # clf = DummyClassifier(strategy='stratified', random_state=0)
        clf = DummyClassifier(strategy='most_frequent', random_state=0)
        inverted_train_labels = inputs.invert_labels(input_data.train_labels)
        clf.fit(input_data.train_data, inverted_train_labels)
        y_pred = clf.predict(input_data.eval_data)

        auc, precision, recall, f1, average_precision, fpr, tpr = \
            metrics_util.get_all_metrics_(input_data.eval_labels, y_pred)

        write_result(outfile,
                     smell + "," + str(auc) + "," + str(precision) + "," + str(recall) + "," + str(f1) + "," + str(
                         average_precision) + "\n") 
开发者ID:tushartushar,项目名称:DeepLearningSmells,代码行数:20,代码来源:rq1_cnn_1d.py

示例4: test_multidimensional_X

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_multidimensional_X():
    """
    Check that the AdaBoost estimators can work with n-dimensional
    data matrix
    """

    from sklearn.dummy import DummyClassifier, DummyRegressor

    rng = np.random.RandomState(0)

    X = rng.randn(50, 3, 3)
    yc = rng.choice([0, 1], 50)
    yr = rng.randn(50)

    boost = AdaBoostClassifier(DummyClassifier(strategy='most_frequent'))
    boost.fit(X, yc)
    boost.predict(X)
    boost.predict_proba(X)

    boost = AdaBoostRegressor(DummyRegressor())
    boost.fit(X, yr)
    boost.predict(X) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:24,代码来源:test_weight_boosting.py

示例5: test_most_frequent_and_prior_strategy

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_most_frequent_and_prior_strategy():
    X = [[0], [0], [0], [0]]  # ignored
    y = [1, 2, 1, 1]

    for strategy in ("most_frequent", "prior"):
        clf = DummyClassifier(strategy=strategy, random_state=0)
        clf.fit(X, y)
        assert_array_equal(clf.predict(X), np.ones(len(X)))
        _check_predict_proba(clf, X, y)

        if strategy == "prior":
            assert_array_almost_equal(clf.predict_proba([X[0]]),
                                      clf.class_prior_.reshape((1, -1)))
        else:
            assert_array_almost_equal(clf.predict_proba([X[0]]),
                                      clf.class_prior_.reshape((1, -1)) > 0.5) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:18,代码来源:test_dummy.py

示例6: test_most_frequent_and_prior_strategy_multioutput

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_most_frequent_and_prior_strategy_multioutput():
    X = [[0], [0], [0], [0]]  # ignored
    y = np.array([[1, 0],
                  [2, 0],
                  [1, 0],
                  [1, 3]])

    n_samples = len(X)

    for strategy in ("prior", "most_frequent"):
        clf = DummyClassifier(strategy=strategy, random_state=0)
        clf.fit(X, y)
        assert_array_equal(clf.predict(X),
                           np.hstack([np.ones((n_samples, 1)),
                                      np.zeros((n_samples, 1))]))
        _check_predict_proba(clf, X, y)
        _check_behavior_2d(clf) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:19,代码来源:test_dummy.py

示例7: test_uniform_strategy_multioutput

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_uniform_strategy_multioutput():
    X = [[0]] * 4  # ignored
    y = np.array([[2, 1],
                  [2, 2],
                  [1, 2],
                  [1, 1]])
    clf = DummyClassifier(strategy="uniform", random_state=0)
    clf.fit(X, y)

    X = [[0]] * 500
    y_pred = clf.predict(X)

    for k in range(y.shape[1]):
        p = np.bincount(y_pred[:, k]) / float(len(X))
        assert_almost_equal(p[1], 0.5, decimal=1)
        assert_almost_equal(p[2], 0.5, decimal=1)
        _check_predict_proba(clf, X, y)

    _check_behavior_2d(clf) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:21,代码来源:test_dummy.py

示例8: test_constant_strategy_multioutput

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_constant_strategy_multioutput():
    X = [[0], [0], [0], [0]]  # ignored
    y = np.array([[2, 3],
                  [1, 3],
                  [2, 3],
                  [2, 0]])

    n_samples = len(X)

    clf = DummyClassifier(strategy="constant", random_state=0,
                          constant=[1, 0])
    clf.fit(X, y)
    assert_array_equal(clf.predict(X),
                       np.hstack([np.ones((n_samples, 1)),
                                  np.zeros((n_samples, 1))]))
    _check_predict_proba(clf, X, y) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:18,代码来源:test_dummy.py

示例9: test_constant_strategy_sparse_target

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_constant_strategy_sparse_target():
    X = [[0]] * 5  # ignored
    y = sp.csc_matrix(np.array([[0, 1],
                                [4, 0],
                                [1, 1],
                                [1, 4],
                                [1, 1]]))

    n_samples = len(X)

    clf = DummyClassifier(strategy="constant", random_state=0, constant=[1, 0])
    clf.fit(X, y)
    y_pred = clf.predict(X)
    assert sp.issparse(y_pred)
    assert_array_equal(y_pred.toarray(), np.hstack([np.ones((n_samples, 1)),
                                                    np.zeros((n_samples, 1))])) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:18,代码来源:test_dummy.py

示例10: test_stratified_strategy_sparse_target

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_stratified_strategy_sparse_target():
    X = [[0]] * 5  # ignored
    y = sp.csc_matrix(np.array([[4, 1],
                                [0, 0],
                                [1, 1],
                                [1, 4],
                                [1, 1]]))

    clf = DummyClassifier(strategy="stratified", random_state=0)
    clf.fit(X, y)

    X = [[0]] * 500
    y_pred = clf.predict(X)
    assert sp.issparse(y_pred)
    y_pred = y_pred.toarray()

    for k in range(y.shape[1]):
        p = np.bincount(y_pred[:, k]) / float(len(X))
        assert_almost_equal(p[1], 3. / 5, decimal=1)
        assert_almost_equal(p[0], 1. / 5, decimal=1)
        assert_almost_equal(p[4], 1. / 5, decimal=1) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:test_dummy.py

示例11: test_most_frequent_and_prior_strategy_sparse_target

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_most_frequent_and_prior_strategy_sparse_target():
    X = [[0]] * 5  # ignored
    y = sp.csc_matrix(np.array([[1, 0],
                                [1, 3],
                                [4, 0],
                                [0, 1],
                                [1, 0]]))

    n_samples = len(X)
    y_expected = np.hstack([np.ones((n_samples, 1)), np.zeros((n_samples, 1))])
    for strategy in ("most_frequent", "prior"):
        clf = DummyClassifier(strategy=strategy, random_state=0)
        clf.fit(X, y)

        y_pred = clf.predict(X)
        assert sp.issparse(y_pred)
        assert_array_equal(y_pred.toarray(), y_expected) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:19,代码来源:test_dummy.py

示例12: test_warning_recursion_non_constant_init

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def test_warning_recursion_non_constant_init():
    # make sure that passing a non-constant init parameter to a GBDT and using
    # recursion method yields a warning.

    gbc = GradientBoostingClassifier(init=DummyClassifier(), random_state=0)
    gbc.fit(X, y)

    with pytest.warns(
            UserWarning,
            match='Using recursion method with a non-constant init predictor'):
        partial_dependence(gbc, X, [0], method='recursion')

    with pytest.warns(
            UserWarning,
            match='Using recursion method with a non-constant init predictor'):
        partial_dependence(gbc, X, [0], method='recursion') 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:18,代码来源:test_partial_dependence.py

示例13: get_methods_multitask

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def get_methods_multitask(tasks_number, header, random_restarts=-1):
    FEATURES_BOW, FEATURES_BROWN, index_task, _=extract_feature_indices(header)
    
    GPCONSTRUCTOR=lambda kernel_constructor, name, random_restarts: MCGP(kernel_constructor=kernel_constructor, 
                                                                         labels=LABELS, name=name, random_restarts=random_restarts)
    
    methodsmultitask=[
             lambda: SklearnBaseline(lambda: DummyClassifier("most_frequent"), "MostFrequentPooled", [0]),
             lambda: GPCONSTRUCTOR(kernel_constructor=lambda: single_task_kernel(FEATURES_BOW, False, "FEATURES_BOW"), 
                                   name="BOWGPjoinedfeaturesPooledLIN", 
                                   random_restarts=random_restarts),
             lambda: GPCONSTRUCTOR(kernel_constructor=lambda: single_task_kernel(FEATURES_BROWN, False, "FEATURES_BROWN"), 
                                   name="BROWNGPjoinedfeaturesPooledLIN", 
                                   random_restarts=random_restarts),
             lambda: GPCONSTRUCTOR(kernel_constructor=lambda: multi_task_kernel(tasks_number, index_task, 
                                                                                single_task_kernel(FEATURES_BROWN, False, "FEATURES_BROWN")), 
                                                                                name="BROWNGPjoinedfeaturesICMLIN", random_restarts=random_restarts),
             lambda: GPCONSTRUCTOR(kernel_constructor=lambda: multi_task_kernel(tasks_number, index_task, 
                                                                                single_task_kernel(FEATURES_BOW, False, "FEATURES_BOW")), 
                                                                                name="BOWGPjoinedfeaturesICMLIN", random_restarts=random_restarts),
             ]
    return methodsmultitask, map(lambda x: x().name, methodsmultitask) 
开发者ID:mlukasik,项目名称:rumour-classification,代码行数:24,代码来源:methods.py

示例14: __init__

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def __init__(self, df,
                 strategy='most_frequent',
                 weight=False,
                 min_ct=0):
        self.logger = logging.getLogger(__name__)
        super(DummyClf, self).__init__()  # call base constructor
        #self.set_min_count(min_ct)
        self.is_weighted_sample = False

        # process data
        #df = self._filter_rows(df)  # filter out low count rows
        df = df.fillna(df.mean())
        self.x, self.y = futils.randomize(df)

        # setup classifier
        self.clf = DummyClassifier(strategy=strategy) 
开发者ID:KarchinLab,项目名称:2020plus,代码行数:18,代码来源:dummy_clf.py

示例15: _call_oracle

# 需要导入模块: from sklearn import dummy [as 别名]
# 或者: from sklearn.dummy import DummyClassifier [as 别名]
def _call_oracle(self, lambda_vec):
        signed_weights = self.obj.signed_weights() + self.constraints.signed_weights(lambda_vec)
        redY = 1 * (signed_weights > 0)
        redW = signed_weights.abs()
        redW = self.n * redW / redW.sum()

        redY_unique = np.unique(redY)

        classifier = None
        if len(redY_unique) == 1:
            logger.debug("redY had single value. Using DummyClassifier")
            classifier = DummyClassifier(strategy='constant',
                                         constant=redY_unique[0])
            self.n_oracle_calls_dummy_returned += 1
        else:
            classifier = pickle.loads(self.pickled_estimator)

        oracle_call_start_time = time()
        classifier.fit(self.X, redY, sample_weight=redW)
        self.oracle_execution_times.append(time() - oracle_call_start_time)
        self.n_oracle_calls += 1

        return classifier 
开发者ID:fairlearn,项目名称:fairlearn,代码行数:25,代码来源:_lagrangian.py


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