示例#1
0
def test_logistic_gradient(coef, X, y):
    p = lr.predict_proba(coef, X)
    assert np.linalg.norm(lr.logistic_gradient(coef, X, p)) < 1e-8

    assert np.linalg.norm(lr.logistic_gradient(np.array([1, 100]), X, y)) > 1

    gradient_norm = np.linalg.norm(lr.logistic_gradient(coef, X, y))
    assert abs(gradient_norm - 0.7071067811865) < 1e-8
示例#2
0
def y(coef, X):
    return lr.predict_proba(coef, X) > 0.5
示例#3
0
def test_predict_proba(coef, X):
    probabilities = lr.predict_proba(coef, X)
    assert abs(probabilities[0] - 0.5) < 1e-8
    assert abs(probabilities[1] - 1) < 1e-8
    assert abs(probabilities[2]) < 1e-8
示例#4
0
 def test_has_converged(self, coef, X):
     lr_model = lr.LogisticRegression()
     p = lr.predict_proba(coef, X)
     assert lr_model._has_converged(coef, X, p)
     assert not lr_model._has_converged(np.array([1, 1000]), X, p)