當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。