Exemplo n.º 1
0
def test_multivariate_normal_equation():
    X = np.array([[1, 2], [2, 3], [4, 5], [6, 7], [7, 8]])
    y = np.array([ 1, 2, 3, 4, 5])
    X_std = (X - np.mean(X)) / X.std()
    y_std = (y - np.mean(y)) / y.std()
    ne_lr = LinearRegression(solver='normal_equation')
    ne_lr.fit(X_std, y_std)
    assert_almost_equal(ne_lr.predict(X_std), np.array(
            [ -1.3054, -0.87029, 0.0000, 0.8703, 1.3054]), 
            decimal=4)
Exemplo n.º 2
0
def test_multivariate_stochastic_gradient_descent():
    X = np.array([[1, 2], [2, 3], [4, 5], [6, 7], [7, 8]])
    y = np.array([ 1, 2, 3, 4, 5])
    X_std = (X - np.mean(X)) / X.std()
    y_std = (y - np.mean(y)) / y.std()
    
    sgd_lr = LinearRegression(solver='sgd', eta=0.001, epochs=1000, random_seed=0)
    sgd_lr.fit(X_std, y_std)
    assert_almost_equal(sgd_lr.predict(X_std), np.array(
            [ -1.3054, -0.87029, 0.0000, 0.8703, 1.3054]), 
            decimal=2)