當前位置: 首頁>>代碼示例>>Python>>正文


Python classifier.LogisticRegression類代碼示例

本文整理匯總了Python中mlxtend.classifier.LogisticRegression的典型用法代碼示例。如果您正苦於以下問題:Python LogisticRegression類的具體用法?Python LogisticRegression怎麽用?Python LogisticRegression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了LogisticRegression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_logistic_regression_gd

def test_logistic_regression_gd():
    t = np.array([0.51, 1.18, 4.40])
    lr = LogisticRegression(epochs=100, eta=0.01, learning='gd', random_seed=0)

    lr.fit(X, y)  # 0, 1 class
    np.testing.assert_almost_equal(lr.w_, t, 2)
    assert((y == lr.predict(X)).all())
開發者ID:beingzy,項目名稱:mlxtend,代碼行數:7,代碼來源:test_logistic_regression.py

示例2: test_print_progress_3

def test_print_progress_3():
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=1,
                            print_progress=3,
                            random_seed=1)
    lr.fit(X, y)
開發者ID:JJLWHarrison,項目名稱:mlxtend,代碼行數:7,代碼來源:test_logistic_regression.py

示例3: test_ary_persistency_in_shuffling

def test_ary_persistency_in_shuffling():
    orig = X.copy()
    lr = LogisticRegression(eta=0.01,
                            epochs=100,
                            minibatches=len(y),
                            l2_lambda=1.0,
                            random_seed=1)
    lr.fit(X, y)
    np.testing.assert_almost_equal(orig, X, 6)
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:9,代碼來源:test_logistic_regression.py

示例4: test_score_function

def test_score_function():
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=1,
                            random_seed=1)

    lr.fit(X, y)
    acc = lr.score(X, y)
    assert acc == 1.0, "Acc: %s" % acc
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:9,代碼來源:test_logistic_regression.py

示例5: test_logistic_regression_sgd

def test_logistic_regression_sgd():
    t = np.array([0.53, 1.2, 4.4])
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=len(y),
                            random_seed=1)

    lr.fit(X, y)  # 0, 1 class
    np.testing.assert_almost_equal(lr.w_, t, 2)
    assert((y == lr.predict(X)).all())
開發者ID:datasci-co,項目名稱:mlxtend,代碼行數:10,代碼來源:test_logistic_regression.py

示例6: test_l2_regularization_gd

def test_l2_regularization_gd():
    lr = LogisticRegression(eta=0.01, epochs=20,
                    learning='gd', regularization='l2',
                    lambda_=1.0, random_seed=0)
    lr.fit(X, y)
    y_pred = lr.predict(X)
    expect_weights = np.array([ 0.252,  1.186,  2.296])

    np.testing.assert_almost_equal(lr.w_, expect_weights, 3)
    acc = sum(y_pred == y) / len(y)
    assert(acc == 1.0)
開發者ID:arunsingh,項目名稱:mlxtend,代碼行數:11,代碼來源:test_logistic_regression.py

示例7: test_predict_proba

def test_predict_proba():
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=1,
                            random_seed=1)

    lr.fit(X, y)
    idx = [0, 48, 99]  # sample labels: 0, 0, 1
    y_pred = lr.predict_proba(X[idx])
    expect = np.array([0.009, 0.012, 0.993])
    np.testing.assert_almost_equal(y_pred, expect, 3)
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:11,代碼來源:test_logistic_regression.py

示例8: test_score_function

def test_score_function():
    t = np.array([0.52, 1.2, 4.4])
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=1,
                            random_seed=1)

    lr.fit(X, y)  # 0, 1 class
    np.testing.assert_almost_equal(lr.w_, t, 2)
    acc = lr.score(X, y)
    assert acc == 1.0, "Acc: %s" % acc
開發者ID:GQiuQi,項目名稱:mlxtend,代碼行數:11,代碼來源:test_logistic_regression.py

示例9: test_logistic_regression_sgd

def test_logistic_regression_sgd():
    w = np.array([[1.18], [4.38]])
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=len(y),
                            random_seed=1)

    lr.fit(X, y)  # 0, 1 class
    np.testing.assert_almost_equal(lr.w_, w, 2)
    y_pred = lr.predict(X)
    acc = np.sum(y == y_pred, axis=0) / float(X.shape[0])
    assert acc == 1.0, "Acc: %s" % acc
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:12,代碼來源:test_logistic_regression.py

示例10: test_logistic_regression_gd

def test_logistic_regression_gd():
    t = np.array([0.52, 1.2, 4.4])
    lr = LogisticRegression(epochs=100,
                            eta=0.01,
                            minibatches=1,
                            random_seed=1)

    lr.fit(X, y)  # 0, 1 class
    np.testing.assert_almost_equal(lr.w_, t, 2)
    y_pred = lr.predict(X)
    acc = np.sum(y == y_pred, axis=0) / float(X.shape[0])
    assert acc == 1.0, "Acc: %s" % acc
開發者ID:blahblueray,項目名稱:mlxtend,代碼行數:12,代碼來源:test_logistic_regression.py

示例11: test_l2_regularization_sgd

def test_l2_regularization_sgd():
    lr = LogisticRegression(eta=0.01,
                            epochs=100,
                            minibatches=len(y),
                            l2_lambda=1.0,
                            random_seed=1)
    lr.fit(X, y)
    y_pred = lr.predict(X)
    expect_weights = np.array([[0.24], [0.35]])

    np.testing.assert_almost_equal(lr.w_, expect_weights, 2)
    y_pred = lr.predict(X)
    acc = np.sum(y == y_pred, axis=0) / float(X.shape[0])
    assert acc == 0.97, "Acc: %s" % acc
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:14,代碼來源:test_logistic_regression.py

示例12: test_l2_regularization_gd

def test_l2_regularization_gd():
    lr = LogisticRegression(eta=0.01,
                            epochs=20,
                            minibatches=1,
                            l2_lambda=1.0,
                            random_seed=1)
    lr.fit(X, y)
    y_pred = lr.predict(X)
    expect_weights = np.array([0.153, 1.055, 2.284])

    np.testing.assert_almost_equal(lr.w_, expect_weights, 3)
    y_pred = lr.predict(X)
    acc = np.sum(y == y_pred, axis=0) / float(X.shape[0])
    assert acc == 1.0, "Acc: %s" % acc
開發者ID:blahblueray,項目名稱:mlxtend,代碼行數:14,代碼來源:test_logistic_regression.py

示例13: test_l2_regularization_gd

def test_l2_regularization_gd():
    lr = LogisticRegression(eta=0.01,
                            epochs=20,
                            minibatches=1,
                            l2_lambda=1.0,
                            regularization='l2',
                            random_seed=1)
    lr.fit(X, y)
    y_pred = lr.predict(X)
    expect_weights = np.array([0.303, 1.066, 2.329])

    np.testing.assert_almost_equal(lr.w_, expect_weights, 3)
    acc = sum(y_pred == y) / len(y)
    assert(acc == 1.0)
開發者ID:datasci-co,項目名稱:mlxtend,代碼行數:14,代碼來源:test_logistic_regression.py

示例14: test_l2_regularization_sgd

def test_l2_regularization_sgd():
    lr = LogisticRegression(eta=0.01,
                            epochs=100,
                            minibatches=len(y),
                            l2_lambda=1.0,
                            regularization='l2',
                            random_seed=1)
    lr.fit(X, y)
    y_pred = lr.predict(X)
    expect_weights = np.array([-2.73e-04, 2.40e-01, 3.53e-01])

    np.testing.assert_almost_equal(lr.w_, expect_weights, 2)
    acc = sum(y_pred == y) / float(len(y))

    assert(acc == 0.97)
開發者ID:datasci-co,項目名稱:mlxtend,代碼行數:15,代碼來源:test_logistic_regression.py

示例15: test_refit_weights

def test_refit_weights():
    w = np.array([[1.2], [4.4]])
    b = np.array([0.52])
    lr = LogisticRegression(epochs=50,
                            eta=0.01,
                            minibatches=1,
                            random_seed=1)

    lr.fit(X, y)
    w1 = lr.w_[0][0]
    w2 = lr.w_[0][0]
    lr.fit(X, y, init_params=False)

    assert w1 != lr.w_[0][0]
    assert w2 != lr.w_[1][0]
    np.testing.assert_almost_equal(lr.w_, w, 2)
    np.testing.assert_almost_equal(lr.b_, b, 2)
開發者ID:CandyPythonFlow,項目名稱:mlxtend,代碼行數:17,代碼來源:test_logistic_regression.py


注:本文中的mlxtend.classifier.LogisticRegression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。