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


Python logistic.LogisticRegression方法代码示例

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


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

示例1: check_l1_min_c

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def check_l1_min_c(X, y, loss, fit_intercept=True, intercept_scaling=None):
    min_c = l1_min_c(X, y, loss, fit_intercept, intercept_scaling)

    clf = {
        'log': LogisticRegression(penalty='l1', solver='liblinear',
                                  multi_class='ovr'),
        'squared_hinge': LinearSVC(loss='squared_hinge',
                                   penalty='l1', dual=False),
    }[loss]

    clf.fit_intercept = fit_intercept
    clf.intercept_scaling = intercept_scaling

    clf.C = min_c
    clf.fit(X, y)
    assert (np.asarray(clf.coef_) == 0).all()
    assert (np.asarray(clf.intercept_) == 0).all()

    clf.C = min_c * 1.01
    clf.fit(X, y)
    assert ((np.asarray(clf.coef_) != 0).any() or
            (np.asarray(clf.intercept_) != 0).any()) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:24,代码来源:test_bounds.py

示例2: initialize_with_logistic_regression

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def initialize_with_logistic_regression(self, zs, xs):
        from sklearn.linear_model.logistic import LogisticRegression
        lr = LogisticRegression(verbose=False, multi_class="multinomial", solver="lbfgs")

        # Make the covariates
        K, D = self.num_states, self.covariate_dim
        zs = zs if isinstance(zs, np.ndarray) else np.concatenate(zs, axis=0)
        xs = xs if isinstance(xs, np.ndarray) else np.concatenate(xs, axis=0)
        assert zs.shape[0] == xs.shape[0]
        assert zs.ndim == 1 and zs.dtype == np.int32 and zs.min() >= 0 and zs.max() < K
        assert xs.ndim == 2 and xs.shape[1] == D

        lr_X = xs[:-1]
        lr_y = zs[1:]
        lr.fit(lr_X, lr_y)

        # Now convert the logistic regression into weights
        used = np.bincount(zs, minlength=K) > 0
        self.W = np.zeros((D, K))
        self.W[:, used] = lr.coef_.T
        b = np.zeros((K,))
        b[used] += lr.intercept_
        b[~used] += -100.
        self.b = b 
开发者ID:slinderman,项目名称:recurrent-slds,代码行数:26,代码来源:transitions.py

示例3: __init__

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def __init__(self, penalty='l2', dual=False, tol=0.0001, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight='balanced', random_state=None, solver='liblinear', max_iter=100, multi_class='ovr', verbose=0, warm_start=False, n_jobs=None):
        self._hyperparams = {
            'penalty': penalty,
            'dual': dual,
            'tol': tol,
            'C': C,
            'fit_intercept': fit_intercept,
            'intercept_scaling': intercept_scaling,
            'class_weight': class_weight,
            'random_state': random_state,
            'solver': solver,
            'max_iter': max_iter,
            'multi_class': multi_class,
            'verbose': verbose,
            'warm_start': warm_start,
            'n_jobs': n_jobs}
        self._wrapped_model = Op(**self._hyperparams) 
开发者ID:IBM,项目名称:lale,代码行数:19,代码来源:logistic_regression.py

示例4: test_pipeline_same_results

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def test_pipeline_same_results(self):
        X, y, Z = self.make_classification(2, 10000, 2000)

        loc_clf = LogisticRegression()
        loc_filter = VarianceThreshold()
        loc_pipe = Pipeline([
            ('threshold', loc_filter),
            ('logistic', loc_clf)
        ])

        dist_clf = SparkLogisticRegression()
        dist_filter = SparkVarianceThreshold()
        dist_pipe = SparkPipeline([
            ('threshold', dist_filter),
            ('logistic', dist_clf)
        ])

        dist_filter.fit(Z)
        loc_pipe.fit(X, y)
        dist_pipe.fit(Z, logistic__classes=np.unique(y))

        assert_true(np.mean(np.abs(
            loc_pipe.predict(X) -
            np.concatenate(dist_pipe.predict(Z[:, 'X']).collect())
        )) < 0.1) 
开发者ID:lensacom,项目名称:sparkit-learn,代码行数:27,代码来源:test_pipeline.py

示例5: check_l1_min_c

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def check_l1_min_c(X, y, loss, fit_intercept=True, intercept_scaling=None):
    min_c = l1_min_c(X, y, loss, fit_intercept, intercept_scaling)

    clf = {
        'log': LogisticRegression(penalty='l1'),
        'squared_hinge': LinearSVC(loss='squared_hinge',
                                   penalty='l1', dual=False),
    }[loss]

    clf.fit_intercept = fit_intercept
    clf.intercept_scaling = intercept_scaling

    clf.C = min_c
    clf.fit(X, y)
    assert_true((np.asarray(clf.coef_) == 0).all())
    assert_true((np.asarray(clf.intercept_) == 0).all())

    clf.C = min_c * 1.01
    clf.fit(X, y)
    assert_true((np.asarray(clf.coef_) != 0).any() or
                (np.asarray(clf.intercept_) != 0).any()) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:23,代码来源:test_bounds.py

示例6: new_grid_search

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def new_grid_search():
    """ Create new GridSearch obj with models pipeline """
    pipeline = Pipeline([
        # TODO some smart preproc can be added here
        (u"clf", LogisticRegression(class_weight="balanced")),
    ])
    search_params = {"clf__C": (1e-4, 1e-2, 1e0, 1e2, 1e4)}
    return GridSearchCV(
        estimator=pipeline,
        param_grid=search_params,
        scoring="recall_macro",
        cv=10,
        n_jobs=-1,
        verbose=3,
    ) 
开发者ID:llSourcell,项目名称:AI_for_Financial_Data,代码行数:17,代码来源:train.py

示例7: create_model

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def create_model():
    from sklearn.linear_model.logistic import LogisticRegression
    clf = LogisticRegression()

    return clf 
开发者ID:PacktPublishing,项目名称:Building-Machine-Learning-Systems-With-Python-Second-Edition,代码行数:7,代码来源:02_ceps_based_classifier.py

示例8: getEstimator

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def getEstimator(scorer_type):
    if scorer_type == 'grad_boost':
        clf = GradientBoostingClassifier(n_estimators=200, random_state=14128, verbose=True)

    if scorer_type == 'svm1': # stochastic gradient decent classifier
        clf = svm.SVC(gamma=0.001, C=100., verbose=True)

    if scorer_type == 'logistic_regression' :
        clf = logistic.LogisticRegression()

    if scorer_type == 'svm3':
        clf = svm.SVC(kernel='poly', C=1.0, probability=True, class_weight='unbalanced')

    if scorer_type == "bayes":
        clf = naive_bayes.GaussianNB()

    if scorer_type == 'voting_hard_svm_gradboost_logistic':
        svm2 = svm.SVC(kernel='linear', C=1.0, probability=True, class_weight='balanced', verbose=True)
        log_reg = logistic.LogisticRegression()
        gradboost = GradientBoostingClassifier(n_estimators=200, random_state=14128, verbose=True)

        clf = VotingClassifier(estimators=[  # ('gb', gb),
            ('svm', svm2),
            ('grad_boost', gradboost),
            ('logisitc_regression', log_reg)
        ],  n_jobs=1,
            voting='hard')

    if scorer_type == 'voting_hard_bayes_gradboost':
        bayes = naive_bayes.GaussianNB()
        gradboost = GradientBoostingClassifier(n_estimators=200, random_state=14128, verbose=True)

        clf = VotingClassifier(estimators=[  # ('gb', gb),
            ('bayes', bayes),
            ('grad_boost', gradboost),
        ],  n_jobs=1,
            voting='hard')

    return clf 
开发者ID:UKPLab,项目名称:coling2018_fake-news-challenge,代码行数:41,代码来源:meta_classifier.py

示例9: get_classification_models

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def get_classification_models():
        models = [
            LogisticRegression(random_state=1),
            RandomForestClassifier(n_estimators=64, max_depth=5, random_state=1),
        ]
        return models 
开发者ID:d909b,项目名称:cxplain,代码行数:8,代码来源:test_util.py

示例10: fit_proxy

# 需要导入模块: from sklearn.linear_model import logistic [as 别名]
# 或者: from sklearn.linear_model.logistic import LogisticRegression [as 别名]
def fit_proxy(explained_model, x, y):
        if isinstance(explained_model, LogisticRegression):
            y_cur = np.argmax(y, axis=-1)
        else:
            y_cur = y
        explained_model.fit(x, y_cur) 
开发者ID:d909b,项目名称:cxplain,代码行数:8,代码来源:test_util.py


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