本文整理汇总了Python中mlxtend.classifier.LogisticRegression.fit方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.fit方法的具体用法?Python LogisticRegression.fit怎么用?Python LogisticRegression.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mlxtend.classifier.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logistic_regression_gd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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())
示例2: test_print_progress_3
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
def test_print_progress_3():
lr = LogisticRegression(epochs=100,
eta=0.01,
minibatches=1,
print_progress=3,
random_seed=1)
lr.fit(X, y)
示例3: test_score_function
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例4: test_ary_persistency_in_shuffling
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)
示例5: test_logistic_regression_sgd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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())
示例6: test_predict_proba
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)
示例7: test_l2_regularization_gd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)
示例8: test_score_function
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例9: test_logistic_regression_sgd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例10: test_logistic_regression_gd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例11: test_l2_regularization_sgd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例12: test_l2_regularization_gd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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
示例13: test_l2_regularization_gd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)
示例14: test_l2_regularization_sgd
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)
示例15: test_refit_weights
# 需要导入模块: from mlxtend.classifier import LogisticRegression [as 别名]
# 或者: from mlxtend.classifier.LogisticRegression import fit [as 别名]
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)