# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 11:49:10 2018

@author: Lionel Massoulard
"""

import pytest

import numpy as np
import pandas as pd

from sklearn.base import is_regressor, is_classifier
from sklearn.exceptions import NotFittedError
from sklearn.model_selection import KFold

from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import RandomForestRegressor
from sklearn.linear_model import LogisticRegression, Ridge
from sklearn.dummy import DummyRegressor


from aikit.models.stacking import OutSamplerTransformer, StackerClassifier, StackerRegressor


def test_OutSamplerTransformer_classifier():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = 1 * (np.random.randn(100) > 0)

    model = OutSamplerTransformer(RandomForestClassifier(n_estimators=10, random_state=123))
    model.fit(X, y)

    p1 = model.model.predict_proba(X)
    p2 = model.transform(X)

    assert not is_classifier(model)
    assert not is_regressor(model)

    assert np.abs(p1[:, 1] - p2[:, 0]).max() <= 10 ** (-10)
    assert p2.shape == (100, 1)

    assert model.get_feature_names() == ["RandomForestClassifier__1"]

    y = np.array(["a", "b", "c"])[np.random.randint(0, 3, 100)]

    model = OutSamplerTransformer(RandomForestClassifier(n_estimators=10, random_state=123))
    model.fit(X, y)

    p1 = model.model.predict_proba(X)
    p2 = model.transform(X)

    assert p1.shape == (100, 3)
    assert p2.shape == (100, 3)

    assert np.abs(p1 - p2).max() <= 10 ** (-10)

    assert model.get_feature_names() == [
        "RandomForestClassifier__a",
        "RandomForestClassifier__b",
        "RandomForestClassifier__c",
    ]


def test_OutSampleTransformer_classifier_unbalanced():
    np.random.seed(123)
    X = np.random.randn(100, 2)
    y = np.array(["AA"] * 33 + ["BB"] * 33 + ["CC"] * 33 + ["DD"])

    model = OutSamplerTransformer(RandomForestClassifier(n_estimators=10, random_state=123))

    p3 = model.fit_transform(X, y)

    assert (p3.max(axis=1) > 0).all()


def test_OutSamplerTransformer_classifier_fit_transform():

    X = np.random.randn(100, 10)
    y = 1 * (np.random.randn(100) > 0)

    cv = KFold(n_splits=10, shuffle=True, random_state=123)

    model = OutSamplerTransformer(LogisticRegression(C=1,random_state=123), cv=cv)
    model.fit(X, y)
    y1 = model.transform(X)

    model = OutSamplerTransformer(LogisticRegression(C=1,random_state=123), cv=cv)
    y2 = model.fit_transform(X, y)

    assert np.abs(y1 - y2).flatten().max() >= 0.01  # vector should be different


def test_OutSamplerTransformer_regressor():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = np.random.randn(100)

    model = OutSamplerTransformer(RandomForestRegressor(n_estimators=10,random_state=123), cv=10)
    model.fit(X, y)

    y1 = model.model.predict(X)
    y2 = model.transform(X)

    assert not is_classifier(model)
    assert not is_regressor(model)

    assert np.abs(y1 - y2[:, 0]).max() <= 10 ** (-10)
    assert y2.shape == (100, 1)

    assert model.get_feature_names() == ["RandomForestRegressor__target"]


def test_OutSamplerTransformer_regressor_fit_transform():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = np.random.randn(100)

    cv = KFold(n_splits=10, shuffle=True, random_state=123)

    model = OutSamplerTransformer(DummyRegressor(), cv=cv)
    model.fit(X, y)
    y1 = model.transform(X)

    model = OutSamplerTransformer(DummyRegressor(), cv=cv)
    y2 = model.fit_transform(X, y)

    assert np.abs(y1 - y2).flatten().max() >= 0.01  # vector should be different


def test_approx_cross_validation_OutSamplerTransformer_regressor():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = np.random.randn(100)

    model = OutSamplerTransformer(RandomForestRegressor(random_state=123), cv=10)

    cv_res, yhat = model.approx_cross_validation(X, y, cv=10, method="transform", no_scoring=True)

    assert cv_res is None
    assert yhat.ndim == 2
    assert yhat.shape == (y.shape[0], 1)

    with pytest.raises(NotFittedError):
        model.transform(X)

    cv = KFold(n_splits=10, shuffle=True, random_state=123)

    model = OutSamplerTransformer(DummyRegressor(), cv=cv)
    yhat1 = model.fit_transform(X, y)

    cv_res, yhat2 = model.approx_cross_validation(X, y, cv=cv, method="transform", no_scoring=True, return_predict=True)
    # Approx cross val and fit transform should return the same thing here
    assert np.abs((yhat1 - yhat2).flatten()).max() <= 10 ** (-5)

    yhat3 = np.zeros((y.shape[0], 1))

    for train, test in cv.split(X, y):
        model = DummyRegressor()
        model.fit(X[train, :], y[train])

        yhat3[test, 0] = model.predict(X[test, :])

    assert np.abs((yhat1 - yhat3).flatten()).max() <= 10 ** (-5)
    assert np.abs((yhat1 - yhat2).flatten()).max() <= 10 ** (-5)


def test_approx_cross_validation_OutSamplerTransformer_classifier():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = 1 * (np.random.randn(100) > 0)

    model = OutSamplerTransformer(RandomForestClassifier(random_state=123), cv=10)

    cv_res, yhat = model.approx_cross_validation(X, y, cv=10, method="transform", no_scoring=True)

    assert cv_res is None
    assert yhat.ndim == 2
    assert yhat.shape == (y.shape[0], 1)

    with pytest.raises(NotFittedError):
        model.transform(X)

    with pytest.raises(NotFittedError):
        model.model.predict(X)

    cv = KFold(n_splits=10, shuffle=True, random_state=123)
    model = OutSamplerTransformer(LogisticRegression(C=1,random_state=123), cv=cv)
    yhat1 = model.fit_transform(X, y)

    model = OutSamplerTransformer(LogisticRegression(C=1,random_state=123), cv=cv)
    cv_res, yhat2 = model.approx_cross_validation(X, y, cv=cv, method="transform", no_scoring=True, return_predict=True)

    # Approx cross val and fit transform should return the same thing here
    assert np.abs((yhat1 - yhat2).flatten()).max() <= 10 ** (-5)

    yhat3 = np.zeros((y.shape[0], 1))

    for train, test in cv.split(X, y):
        model = LogisticRegression()
        model.fit(X[train, :], y[train])

        yhat3[test, 0] = model.predict_proba(X[test, :])[:, 1]

    assert np.abs((yhat1 - yhat3).flatten()).max() <= 10 ** (-5)
    assert np.abs((yhat1 - yhat2).flatten()).max() <= 10 ** (-5)


def test_StackerRegressor():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = np.random.randn(100)

    stacker = StackerRegressor(models=[RandomForestRegressor(n_estimators=10,random_state=123), Ridge(random_state=123)], cv=10, blender=Ridge(random_state=123))

    stacker.fit(X, y)

    yhat = stacker.predict(X)

    assert yhat.ndim == 1
    assert yhat.shape[0] == X.shape[0]

    assert is_regressor(stacker)
    assert not is_classifier(stacker)

    with pytest.raises(AttributeError):
        stacker.predict_proba(X)

    with pytest.raises(AttributeError):
        stacker.classes_


def test_StackerClassifier():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = 1 * (np.random.randn(100) > 0)

    stacker = StackerClassifier(
        models=[RandomForestClassifier(random_state=123), LogisticRegression(C=1,random_state=123)], cv=10, blender=LogisticRegression(C=1,random_state=123)
    )

    stacker.fit(X, y)

    yhat = stacker.predict(X)

    assert yhat.ndim == 1
    assert yhat.shape[0] == X.shape[0]

    assert list(set(yhat)) == [0, 1]
    assert list(stacker.classes_) == [0, 1]

    yhat_proba = stacker.predict_proba(X)

    assert yhat_proba.shape == (y.shape[0], 2)

    assert not is_regressor(stacker)
    assert is_classifier(stacker)


def test_approx_cross_validation_StackerRegressor():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = np.random.randn(100)

    stacker = StackerRegressor(models=[RandomForestRegressor(n_estimators=10,random_state=123), Ridge(random_state=123)], cv=10, blender=Ridge(random_state=123))

    cv_res, yhat = stacker.approx_cross_validation(
        X, y, cv=10, method="predict", scoring=["neg_mean_squared_error"], return_predict=True, verbose=False
    )

    assert cv_res is not None
    assert isinstance(cv_res, pd.DataFrame)
    assert cv_res.shape[0] == 10
    assert "test_neg_mean_squared_error" in cv_res
    assert "train_neg_mean_squared_error" in cv_res

    assert yhat.ndim == 1
    assert yhat.shape[0] == y.shape[0]

    with pytest.raises(NotFittedError):
        stacker.predict(X)

    for m in stacker.models:
        with pytest.raises(NotFittedError):
            m.predict(X)


def test_approx_cross_validation_StackerClassifier():

    np.random.seed(123)
    X = np.random.randn(100, 10)
    y = 1 * (np.random.randn(100) > 0)

    stacker = StackerClassifier(
        models=[RandomForestClassifier(n_estimators=10,random_state=123), LogisticRegression(C=1,random_state=123)], cv=10, blender=LogisticRegression(C=1,random_state=123)
    )

    cv_res, yhat = stacker.approx_cross_validation(
        X, y, cv=10, method="predict_proba", scoring=["accuracy"], return_predict=True, verbose=False
    )

    assert cv_res is not None
    assert isinstance(cv_res, pd.DataFrame)
    assert cv_res.shape[0] == 10
    assert "test_accuracy" in cv_res
    assert "train_accuracy" in cv_res

    assert yhat.ndim == 2
    assert yhat.shape == (y.shape[0], 2)

    with pytest.raises(NotFittedError):
        stacker.predict(X)

    for m in stacker.models:
        with pytest.raises(NotFittedError):
            m.predict(X)


def _verif_all():
    test_OutSamplerTransformer_classifier()
    test_OutSamplerTransformer_regressor()

    test_OutSamplerTransformer_classifier_fit_transform()
    test_OutSamplerTransformer_regressor_fit_transform()

    test_approx_cross_validation_OutSamplerTransformer_regressor()
    test_approx_cross_validation_OutSamplerTransformer_classifier()

    test_StackerClassifier()
    test_StackerRegressor()

    test_approx_cross_validation_StackerClassifier()
    test_approx_cross_validation_StackerRegressor()

[((644, 663), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (658, 663), True, 'import numpy as np\n'), ((672, 696), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (687, 696), True, 'import numpy as np\n'), ((1734, 1753), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (1748, 1753), True, 'import numpy as np\n'), ((1762, 1785), 'numpy.random.randn', 'np.random.randn', (['(100)', '(2)'], {}), '(100, 2)\n', (1777, 1785), True, 'import numpy as np\n'), ((1794, 1852), 'numpy.array', 'np.array', (["(['AA'] * 33 + ['BB'] * 33 + ['CC'] * 33 + ['DD'])"], {}), "(['AA'] * 33 + ['BB'] * 33 + ['CC'] * 33 + ['DD'])\n", (1802, 1852), True, 'import numpy as np\n'), ((2092, 2116), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (2107, 2116), True, 'import numpy as np\n'), ((2166, 2216), 'sklearn.model_selection.KFold', 'KFold', ([], {'n_splits': '(10)', 'shuffle': '(True)', 'random_state': '(123)'}), '(n_splits=10, shuffle=True, random_state=123)\n', (2171, 2216), False, 'from sklearn.model_selection import KFold\n'), ((2601, 2620), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (2615, 2620), True, 'import numpy as np\n'), ((2629, 2653), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (2644, 2653), True, 'import numpy as np\n'), ((2662, 2682), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (2677, 2682), True, 'import numpy as np\n'), ((3162, 3181), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (3176, 3181), True, 'import numpy as np\n'), ((3190, 3214), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (3205, 3214), True, 'import numpy as np\n'), ((3223, 3243), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (3238, 3243), True, 'import numpy as np\n'), ((3254, 3304), 'sklearn.model_selection.KFold', 'KFold', ([], {'n_splits': '(10)', 'shuffle': '(True)', 'random_state': '(123)'}), '(n_splits=10, shuffle=True, random_state=123)\n', (3259, 3304), False, 'from sklearn.model_selection import KFold\n'), ((3665, 3684), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (3679, 3684), True, 'import numpy as np\n'), ((3693, 3717), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (3708, 3717), True, 'import numpy as np\n'), ((3726, 3746), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (3741, 3746), True, 'import numpy as np\n'), ((4102, 4152), 'sklearn.model_selection.KFold', 'KFold', ([], {'n_splits': '(10)', 'shuffle': '(True)', 'random_state': '(123)'}), '(n_splits=10, shuffle=True, random_state=123)\n', (4107, 4152), False, 'from sklearn.model_selection import KFold\n'), ((4526, 4551), 'numpy.zeros', 'np.zeros', (['(y.shape[0], 1)'], {}), '((y.shape[0], 1))\n', (4534, 4551), True, 'import numpy as np\n'), ((4925, 4944), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (4939, 4944), True, 'import numpy as np\n'), ((4953, 4977), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (4968, 4977), True, 'import numpy as np\n'), ((5445, 5495), 'sklearn.model_selection.KFold', 'KFold', ([], {'n_splits': '(10)', 'shuffle': '(True)', 'random_state': '(123)'}), '(n_splits=10, shuffle=True, random_state=123)\n', (5450, 5495), False, 'from sklearn.model_selection import KFold\n'), ((5976, 6001), 'numpy.zeros', 'np.zeros', (['(y.shape[0], 1)'], {}), '((y.shape[0], 1))\n', (5984, 6001), True, 'import numpy as np\n'), ((6351, 6370), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (6365, 6370), True, 'import numpy as np\n'), ((6379, 6403), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (6394, 6403), True, 'import numpy as np\n'), ((6412, 6432), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (6427, 6432), True, 'import numpy as np\n'), ((6728, 6749), 'sklearn.base.is_regressor', 'is_regressor', (['stacker'], {}), '(stacker)\n', (6740, 6749), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((6965, 6984), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (6979, 6984), True, 'import numpy as np\n'), ((6993, 7017), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (7008, 7017), True, 'import numpy as np\n'), ((7596, 7618), 'sklearn.base.is_classifier', 'is_classifier', (['stacker'], {}), '(stacker)\n', (7609, 7618), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((7679, 7698), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (7693, 7698), True, 'import numpy as np\n'), ((7707, 7731), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (7722, 7731), True, 'import numpy as np\n'), ((7740, 7760), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (7755, 7760), True, 'import numpy as np\n'), ((8598, 8617), 'numpy.random.seed', 'np.random.seed', (['(123)'], {}), '(123)\n', (8612, 8617), True, 'import numpy as np\n'), ((8626, 8650), 'numpy.random.randn', 'np.random.randn', (['(100)', '(10)'], {}), '(100, 10)\n', (8641, 8650), True, 'import numpy as np\n'), ((771, 828), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (793, 828), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((933, 953), 'sklearn.base.is_classifier', 'is_classifier', (['model'], {}), '(model)\n', (946, 953), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((969, 988), 'sklearn.base.is_regressor', 'is_regressor', (['model'], {}), '(model)\n', (981, 988), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((1162, 1187), 'numpy.array', 'np.array', (["['a', 'b', 'c']"], {}), "(['a', 'b', 'c'])\n", (1170, 1187), True, 'import numpy as np\n'), ((1253, 1310), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (1275, 1310), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((1888, 1945), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (1910, 1945), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((2252, 2293), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (2270, 2293), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((2384, 2425), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (2402, 2425), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((2718, 2774), 'sklearn.ensemble.RandomForestRegressor', 'RandomForestRegressor', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (2739, 2774), False, 'from sklearn.ensemble import RandomForestRegressor\n'), ((2879, 2899), 'sklearn.base.is_classifier', 'is_classifier', (['model'], {}), '(model)\n', (2892, 2899), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((2915, 2934), 'sklearn.base.is_regressor', 'is_regressor', (['model'], {}), '(model)\n', (2927, 2934), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((3340, 3356), 'sklearn.dummy.DummyRegressor', 'DummyRegressor', ([], {}), '()\n', (3354, 3356), False, 'from sklearn.dummy import DummyRegressor\n'), ((3448, 3464), 'sklearn.dummy.DummyRegressor', 'DummyRegressor', ([], {}), '()\n', (3462, 3464), False, 'from sklearn.dummy import DummyRegressor\n'), ((3782, 3821), 'sklearn.ensemble.RandomForestRegressor', 'RandomForestRegressor', ([], {'random_state': '(123)'}), '(random_state=123)\n', (3803, 3821), False, 'from sklearn.ensemble import RandomForestRegressor\n'), ((4034, 4063), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (4047, 4063), False, 'import pytest\n'), ((4188, 4204), 'sklearn.dummy.DummyRegressor', 'DummyRegressor', ([], {}), '()\n', (4202, 4204), False, 'from sklearn.dummy import DummyRegressor\n'), ((4608, 4624), 'sklearn.dummy.DummyRegressor', 'DummyRegressor', ([], {}), '()\n', (4622, 4624), False, 'from sklearn.dummy import DummyRegressor\n'), ((5052, 5092), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'random_state': '(123)'}), '(random_state=123)\n', (5074, 5092), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((5305, 5334), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (5318, 5334), False, 'import pytest\n'), ((5373, 5402), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (5386, 5402), False, 'import pytest\n'), ((5530, 5571), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (5548, 5571), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((5652, 5693), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (5670, 5693), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((6058, 6078), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {}), '()\n', (6076, 6078), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((6765, 6787), 'sklearn.base.is_classifier', 'is_classifier', (['stacker'], {}), '(stacker)\n', (6778, 6787), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((6798, 6827), 'pytest.raises', 'pytest.raises', (['AttributeError'], {}), '(AttributeError)\n', (6811, 6827), False, 'import pytest\n'), ((6872, 6901), 'pytest.raises', 'pytest.raises', (['AttributeError'], {}), '(AttributeError)\n', (6885, 6901), False, 'import pytest\n'), ((7563, 7584), 'sklearn.base.is_regressor', 'is_regressor', (['stacker'], {}), '(stacker)\n', (7575, 7584), False, 'from sklearn.base import is_regressor, is_classifier\n'), ((8380, 8409), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (8393, 8409), False, 'import pytest\n'), ((9325, 9354), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (9338, 9354), False, 'import pytest\n'), ((710, 730), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (725, 730), True, 'import numpy as np\n'), ((1188, 1216), 'numpy.random.randint', 'np.random.randint', (['(0)', '(3)', '(100)'], {}), '(0, 3, 100)\n', (1205, 1216), True, 'import numpy as np\n'), ((2130, 2150), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (2145, 2150), True, 'import numpy as np\n'), ((4991, 5011), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (5006, 5011), True, 'import numpy as np\n'), ((6571, 6594), 'sklearn.linear_model.Ridge', 'Ridge', ([], {'random_state': '(123)'}), '(random_state=123)\n', (6576, 6594), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((7031, 7051), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (7046, 7051), True, 'import numpy as np\n'), ((7207, 7248), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (7225, 7248), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((7899, 7922), 'sklearn.linear_model.Ridge', 'Ridge', ([], {'random_state': '(123)'}), '(random_state=123)\n', (7904, 7922), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((8481, 8510), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (8494, 8510), False, 'import pytest\n'), ((8664, 8684), 'numpy.random.randn', 'np.random.randn', (['(100)'], {}), '(100)\n', (8679, 8684), True, 'import numpy as np\n'), ((8856, 8897), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (8874, 8897), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((9426, 9455), 'pytest.raises', 'pytest.raises', (['NotFittedError'], {}), '(NotFittedError)\n', (9439, 9455), False, 'import pytest\n'), ((1001, 1032), 'numpy.abs', 'np.abs', (['(p1[:, (1)] - p2[:, (0)])'], {}), '(p1[:, (1)] - p2[:, (0)])\n', (1007, 1032), True, 'import numpy as np\n'), ((1476, 1491), 'numpy.abs', 'np.abs', (['(p1 - p2)'], {}), '(p1 - p2)\n', (1482, 1491), True, 'import numpy as np\n'), ((2947, 2970), 'numpy.abs', 'np.abs', (['(y1 - y2[:, (0)])'], {}), '(y1 - y2[:, (0)])\n', (2953, 2970), True, 'import numpy as np\n'), ((6473, 6529), 'sklearn.ensemble.RandomForestRegressor', 'RandomForestRegressor', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (6494, 6529), False, 'from sklearn.ensemble import RandomForestRegressor\n'), ((6530, 6553), 'sklearn.linear_model.Ridge', 'Ridge', ([], {'random_state': '(123)'}), '(random_state=123)\n', (6535, 6553), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((7107, 7147), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'random_state': '(123)'}), '(random_state=123)\n', (7129, 7147), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((7149, 7190), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (7167, 7190), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((7801, 7857), 'sklearn.ensemble.RandomForestRegressor', 'RandomForestRegressor', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (7822, 7857), False, 'from sklearn.ensemble import RandomForestRegressor\n'), ((7858, 7881), 'sklearn.linear_model.Ridge', 'Ridge', ([], {'random_state': '(123)'}), '(random_state=123)\n', (7863, 7881), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((8740, 8797), 'sklearn.ensemble.RandomForestClassifier', 'RandomForestClassifier', ([], {'n_estimators': '(10)', 'random_state': '(123)'}), '(n_estimators=10, random_state=123)\n', (8762, 8797), False, 'from sklearn.ensemble import RandomForestClassifier\n'), ((8798, 8839), 'sklearn.linear_model.LogisticRegression', 'LogisticRegression', ([], {'C': '(1)', 'random_state': '(123)'}), '(C=1, random_state=123)\n', (8816, 8839), False, 'from sklearn.linear_model import LogisticRegression, Ridge\n'), ((2480, 2495), 'numpy.abs', 'np.abs', (['(y1 - y2)'], {}), '(y1 - y2)\n', (2486, 2495), True, 'import numpy as np\n'), ((3520, 3535), 'numpy.abs', 'np.abs', (['(y1 - y2)'], {}), '(y1 - y2)\n', (3526, 3535), True, 'import numpy as np\n')]