Ejemplo n.º 1
0
def test_logistic_regression_weights():
    """[Utils] LogisticRegression: check weights."""
    w = np.array([[-0.81643357, 0.76923077], [-0.52156177, 0.51282051],
                  [0.33799534, -0.28205128]])

    lr = LogisticRegression()
    lr.fit(X, z)

    np.testing.assert_array_almost_equal(lr.coef_, w)
Ejemplo n.º 2
0
def test_logistic_regression_preds_labels():
    """[Utils] LogisticRegression: check label predictions."""
    g = np.array([1., 1., 1., 1., 2., 2., 2., 3., 3., 3., 3., 3.])

    p = LogisticRegression().fit(X, z).predict(X)

    np.testing.assert_array_equal(p, g)
Ejemplo n.º 3
0
def test_logistic_regression_preds_proba():
    """[Utils] LogisticRegression: check label predictions."""

    g = np.array([[0.68335447, 0.62546744, 0.42995095],
                  [0.66258275, 0.62136312, 0.45756156],
                  [0.64116395, 0.61724135, 0.48543536],
                  [0.61916698, 0.61310265, 0.51340005],
                  [0.59666983, 0.60894755, 0.54128111],
                  [0.57375858, 0.60477659, 0.56890605],
                  [0.55052625, 0.60059033, 0.59610873],
                  [0.5270714, 0.59638931, 0.62273319],
                  [0.50349645, 0.59217411, 0.64863706],
                  [0.47990593, 0.58794531, 0.67369429],
                  [0.45640469, 0.58370348, 0.69779712],
                  [0.43309595, 0.57944923, 0.72085727]])

    p = LogisticRegression().fit(X, z).predict_proba(X)

    np.testing.assert_array_almost_equal(p, g)
Ejemplo n.º 4
0
def test_logistic_regression_not_fitted():
    """[Utils] LogisticRegression: check raises if not fitted."""
    np.testing.assert_raises(NotFittedError, LogisticRegression().predict, X)
Ejemplo n.º 5
0
"""
import os
import numpy as np
from mlens.index import INDEXERS
from mlens.testing.dummy import Data, ECM
from mlens.utils.dummy import Scale, LogisticRegression
from mlens.parallel import make_group, Layer, run
from mlens.externals.sklearn.base import clone
try:
    from contextlib import redirect_stdout
except ImportError:
    from mlens.externals.fixes import redirect as redirect_stdout


PREPROCESSING_1 = {'no1': [], 'sc1': [('scale', Scale())]}
ESTIMATORS_PROBA_1 = {'sc1': [('offs1', LogisticRegression(offset=2)),
                              ('null1', LogisticRegression())],
                      'no1': [('offs1', LogisticRegression(offset=2)),
                              ('null1', LogisticRegression())]}

PREPROCESSING_2 = {'no2': [], 'sc2': [('scale', Scale())]}
ESTIMATORS_PROBA_2 = {'sc2': [('offs2', LogisticRegression(offset=2)),
                             ('null2', LogisticRegression())],
                      'no2': [('offs2', LogisticRegression(offset=2)),
                             ('null2', LogisticRegression())]}


def scorer(p, y): return np.mean(p - y)


data = Data('stack', True, True)
Ejemplo n.º 6
0
"""
import os
import numpy as np
from mlens.index import INDEXERS
from mlens.testing.dummy import Data, ECM
from mlens.utils.dummy import Scale, LogisticRegression
from mlens.parallel import make_group, Layer, run
from mlens.externals.sklearn.base import clone
try:
    from contextlib import redirect_stdout
except ImportError:
    from mlens.externals.fixes import redirect as redirect_stdout

PREPROCESSING_1 = {'no1': [], 'sc1': [('scale', Scale())]}
ESTIMATORS_PROBA_1 = {
    'sc1': [('offs1', LogisticRegression(offset=2)),
            ('null1', LogisticRegression())],
    'no1': [('offs1', LogisticRegression(offset=2)),
            ('null1', LogisticRegression())]
}

PREPROCESSING_2 = {'no2': [], 'sc2': [('scale', Scale())]}
ESTIMATORS_PROBA_2 = {
    'sc2': [('offs2', LogisticRegression(offset=2)),
            ('null2', LogisticRegression())],
    'no2': [('offs2', LogisticRegression(offset=2)),
            ('null2', LogisticRegression())]
}


def scorer(p, y):