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


Python linear_model.LogisticRegressionCV方法代码示例

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


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

示例1: train_lr_rfeinman

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def train_lr_rfeinman(densities_pos, densities_neg, uncerts_pos, uncerts_neg):
    """
    TODO
    :param densities_pos:
    :param densities_neg:
    :param uncerts_pos:
    :param uncerts_neg:
    :return:
    """
    values_neg = np.concatenate(
        (densities_neg.reshape((1, -1)),
         uncerts_neg.reshape((1, -1))),
        axis=0).transpose([1, 0])
    values_pos = np.concatenate(
        (densities_pos.reshape((1, -1)),
         uncerts_pos.reshape((1, -1))),
        axis=0).transpose([1, 0])

    values = np.concatenate((values_neg, values_pos))
    labels = np.concatenate(
        (np.zeros_like(densities_neg), np.ones_like(densities_pos)))

    lr = LogisticRegressionCV(n_jobs=-1).fit(values, labels)

    return values, labels, lr 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:27,代码来源:util.py

示例2: __init__

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def __init__(self, G, labels, nw_name, num_shuffles, traintest_fracs, trainvalid_frac, dim=128,
                 nc_model=None):
        # General evaluation parameters
        self.G = G
        self.labels = labels[np.argsort(labels[:, 0]), :]
        self.nw_name = nw_name
        self.traintest_fracs = traintest_fracs
        self.trainvalid_frac = trainvalid_frac
        self.shuffles = self._init_shuffles(num_shuffles)
        self.dim = dim
        if nc_model is None:
            self.nc_model = LogisticRegressionCV(Cs=10, cv=3, penalty='l2', multi_class='ovr')
        else:
            self.nc_model = nc_model
        # Run some simple input checks
        self._check_labels() 
开发者ID:Dru-Mara,项目名称:EvalNE,代码行数:18,代码来源:evaluator.py

示例3: lr_with_scale

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def lr_with_scale():
    """
    Submission: lr_with_scale_0620_04.csv
    E_val: <missing>
    E_in: 0.857351105162
    E_out: 0.854097855439904
    """
    from sklearn.linear_model import LogisticRegressionCV
    from sklearn.preprocessing import StandardScaler
    from sklearn.pipeline import Pipeline

    X = util.fetch(util.cache_path('train_X_before_2014-08-01_22-00-47'))
    y = util.fetch(util.cache_path('train_y_before_2014-08-01_22-00-47'))

    raw_scaler = StandardScaler()
    raw_scaler.fit(X)
    X_scaled = raw_scaler.transform(X)

    clf = LogisticRegressionCV(cv=10, scoring='roc_auc', n_jobs=-1)
    clf.fit(X_scaled, y)
    print(auc_score(clf, X_scaled, y))
    to_submission(Pipeline([('scale_raw', raw_scaler),
                            ('lr', clf)]), 'lr_with_scale_0620_04') 
开发者ID:its-fun,项目名称:kddcup2015,代码行数:25,代码来源:modeling.py

示例4: test_model_logistic_regression_cv_binary_class

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def test_model_logistic_regression_cv_binary_class(self):
        model, X = fit_classification_model(
            linear_model.LogisticRegressionCV(max_iter=100), 2)
        model_onnx = convert_sklearn(
            model, "logistic regression cv",
            [("input", FloatTensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnLogitisticCVRegressionBinary",
            # Operator cast-1 is not implemented in onnxruntime
            allow_failure="StrictVersion(onnx.__version__)"
                          " < StrictVersion('1.3') or "
                          "StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_glm_classifier_converter.py

示例5: test_model_logistic_regression_cv_int

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def test_model_logistic_regression_cv_int(self):
        model, X = fit_classification_model(
            linear_model.LogisticRegressionCV(max_iter=100), 4, is_int=True)
        model_onnx = convert_sklearn(
            model, "logistic regression cv",
            [("input", Int64TensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnLogitisticRegressionCVInt",
            # Operator cast-1 is not implemented in onnxruntime
            allow_failure="StrictVersion(onnx.__version__)"
                          " < StrictVersion('1.3') or "
                          "StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_glm_classifier_converter.py

示例6: test_model_logistic_regression_cv_bool

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def test_model_logistic_regression_cv_bool(self):
        model, X = fit_classification_model(
            linear_model.LogisticRegressionCV(max_iter=100), 3, is_bool=True)
        model_onnx = convert_sklearn(
            model, "logistic regression cv",
            [("input", BooleanTensorType([None, X.shape[1]]))])
        self.assertIsNotNone(model_onnx)
        dump_data_and_model(
            X,
            model,
            model_onnx,
            basename="SklearnLogitisticRegressionCVBool",
            # Operator cast-1 is not implemented in onnxruntime
            allow_failure="StrictVersion(onnx.__version__)"
                          " < StrictVersion('1.3') or "
                          "StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_glm_classifier_converter.py

示例7: test_regularization

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def test_regularization():
    """Test for fitting the model."""
    X = rnd.randn(10, 2)
    y = np.hstack((-np.ones((5,)), np.ones((5,))))
    Z = rnd.randn(10, 2) + 1
    clf = ImportanceWeightedClassifier(loss_function='lr',
                                       l2_regularization=None)
    assert isinstance(clf.clf, LogisticRegressionCV)
    clf = ImportanceWeightedClassifier(loss_function='lr',
                                       l2_regularization=1.0)
    assert isinstance(clf.clf, LogisticRegression) 
开发者ID:wmkouw,项目名称:libTLDA,代码行数:13,代码来源:test_iw.py

示例8: train_lr

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def train_lr(X, y):
    """
    TODO
    :param X: the data samples
    :param y: the labels
    :return:
    """
    lr = LogisticRegressionCV(n_jobs=-1).fit(X, y)
    return lr 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:11,代码来源:util.py

示例9: compute_roc_auc

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def compute_roc_auc(test_sa, adv_sa, split=1000):
    tr_test_sa = np.array(test_sa[:split])
    tr_adv_sa = np.array(adv_sa[:split])

    tr_values = np.concatenate(
        (tr_test_sa.reshape(-1, 1), tr_adv_sa.reshape(-1, 1)), axis=0
    )
    tr_labels = np.concatenate(
        (np.zeros_like(tr_test_sa), np.ones_like(tr_adv_sa)), axis=0
    )

    lr = LogisticRegressionCV(cv=5, n_jobs=-1).fit(tr_values, tr_labels)

    ts_test_sa = np.array(test_sa[split:])
    ts_adv_sa = np.array(adv_sa[split:])
    values = np.concatenate(
        (ts_test_sa.reshape(-1, 1), ts_adv_sa.reshape(-1, 1)), axis=0
    )
    labels = np.concatenate(
        (np.zeros_like(ts_test_sa), np.ones_like(ts_adv_sa)), axis=0
    )

    probs = lr.predict_proba(values)[:, 1]

    _, _, auc_score = compute_roc(
        probs_neg=probs[: (len(test_sa) - split)],
        probs_pos=probs[(len(test_sa) - split) :],
    )

    return auc_score 
开发者ID:coinse,项目名称:sadl,代码行数:32,代码来源:utils.py

示例10: lp_model

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def lp_model(self):
        model = self._config.get('GENERAL', 'lp_model')
        if model == 'LogisticRegression':
            return LogisticRegression(solver='liblinear')
        elif model == 'LogisticRegressionCV':
            return LogisticRegressionCV(Cs=10, cv=5, penalty='l2', scoring='roc_auc', solver='lbfgs', max_iter=100)
        elif model == 'DecisionTreeClassifier':
            return DecisionTreeClassifier()
        elif model == 'SVM':
            parameters = {'C': [0.1, 1, 10, 100, 1000]}
            return GridSearchCV(LinearSVC(), parameters, cv=5)
        else:
            return util.auto_import(model) 
开发者ID:Dru-Mara,项目名称:EvalNE,代码行数:15,代码来源:pipeline.py

示例11: test_changed_only

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def test_changed_only():
    # Make sure the changed_only param is correctly used
    set_config(print_changed_only=True)
    lr = LogisticRegression(C=99)
    expected = """LogisticRegression(C=99)"""
    assert lr.__repr__() == expected

    # Check with a repr that doesn't fit on a single line
    lr = LogisticRegression(C=99, class_weight=.4, fit_intercept=False,
                            tol=1234, verbose=True)
    expected = """
LogisticRegression(C=99, class_weight=0.4, fit_intercept=False, tol=1234,
                   verbose=True)"""
    expected = expected[1:]  # remove first \n
    assert lr.__repr__() == expected

    imputer = SimpleImputer(missing_values=0)
    expected = """SimpleImputer(missing_values=0)"""
    assert imputer.__repr__() == expected

    # Defaults to np.NaN, trying with float('NaN')
    imputer = SimpleImputer(missing_values=float('NaN'))
    expected = """SimpleImputer()"""
    assert imputer.__repr__() == expected

    # make sure array parameters don't throw error (see #13583)
    repr(LogisticRegressionCV(Cs=np.array([0.1, 1])))

    set_config(print_changed_only=False) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:31,代码来源:test_pprint.py

示例12: lr

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def lr():
    """
    Submission: lr_0618.csv
    E_val: <missing>
    E_in: <missing>
    E_out: 0.8119110960575004
    """
    from sklearn.linear_model import LogisticRegressionCV
    X = util.fetch(util.cache_path('train_X_before_2014-08-01_22-00-47'))
    y = util.fetch(util.cache_path('train_y_before_2014-08-01_22-00-47'))
    clf = LogisticRegressionCV(cv=10, scoring='roc_auc', n_jobs=-1)
    clf.fit(X, y)
    print(auc_score(clf, X, y))
    to_submission(clf, 'lr_0618_xxx') 
开发者ID:its-fun,项目名称:kddcup2015,代码行数:16,代码来源:modeling.py

示例13: lr_with_fs

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def lr_with_fs():
    """
    Submission: lr_with_fs_0620_02.csv
    E_val: <missing>
    E_in: 0.856252488379
    E_out: 0.8552577388980213
    """
    from sklearn.linear_model import LogisticRegressionCV
    from sklearn.preprocessing import StandardScaler
    from sklearn.pipeline import Pipeline

    X = util.fetch(util.cache_path('train_X_before_2014-08-01_22-00-47'))
    y = util.fetch(util.cache_path('train_y_before_2014-08-01_22-00-47'))

    raw_scaler = StandardScaler()
    raw_scaler.fit(X)
    X_scaled = raw_scaler.transform(X)

    rfe = util.fetch(util.cache_path('feature_selection.RFE.21'))

    X_pruned = rfe.transform(X_scaled)

    new_scaler = StandardScaler()
    new_scaler.fit(X_pruned)
    X_new = new_scaler.transform(X_pruned)

    clf = LogisticRegressionCV(cv=10, scoring='roc_auc', n_jobs=-1)
    clf.fit(X_new, y)
    print(auc_score(clf, X_new, y))
    to_submission(Pipeline([('scale_raw', raw_scaler),
                            ('rfe', rfe),
                            ('scale_new', new_scaler),
                            ('lr', clf)]), 'lr_with_fs_0620_02') 
开发者ID:its-fun,项目名称:kddcup2015,代码行数:35,代码来源:modeling.py

示例14: getTransition

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def getTransition(self,dTD,dTG,dMb,FCUT=1):
                G = self.getFC()
                dFC = {item[0].upper(): item[1] for item in G}
                etfID = [item[1] for item in self.etf]
                HGL = [item.upper() for item in self.GL]
                dR={0:2,1:-2,2:0} 
                try:
                        [X, Y,U,D] = buildTrain(G, dTG, etfID,self.GL,FCUT)
                        dR = {0: U, 1: D, 2: 0}
                        LR = LogisticRegressionCV(penalty='l1', Cs=[1.5, 2, 3, 4, 5], solver='liblinear', multi_class='ovr')
                        LR.fit(X, Y)
                        CE = LR.coef_
                        petf = parseLR(self.etf, CE)
                        # ---------------------------------------------------------
                        XX = []
                        for i in HGL:
                                if i in dTG:
                                        tfi = dTG[i]
                                        xi = [1 if item in tfi else 0 for item in etfID]
                                else:
                                        xi = [0] * len(etfID)
                                XX.append(xi)
                        YY = LR.predict(XX)
                        self.etf = petf
                        #pdb.set_trace()
                except:
                        YY = [0 if dFC[item] > FCUT else 1 if dFC[item] < -1 * FCUT else 2 for item in HGL]
                YY = [dR[item] for item in YY]
                return YY

        #------------------------------------------------------------------- 
开发者ID:phoenixding,项目名称:scdiff,代码行数:33,代码来源:scdiff.py

示例15: logistic_regression_cv

# 需要导入模块: from sklearn import linear_model [as 别名]
# 或者: from sklearn.linear_model import LogisticRegressionCV [as 别名]
def logistic_regression_cv():
  """Logistic regression with 5 folds cross validation."""
  return LogisticRegressionCV(Cs=10, cv=KFold(n_splits=5)) 
开发者ID:google-research,项目名称:disentanglement_lib,代码行数:5,代码来源:utils.py


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