示例#1
0
def test_ftrl_set_wrong_nepochs_type():
    ft = Ftrl()
    with pytest.raises(TypeError) as e:
        ft.nepochs = "-10.0"
    assert ("Expected an integer, instead got <class 'str'>" == str(e.value))
示例#2
0
def test_ftrl_construct_wrong_lambda2_value():
    with pytest.raises(ValueError) as e:
        noop(Ftrl(lambda2=-1.0))
    assert ("Argument `lambda2` in Ftrl() constructor should be greater than "
            "or equal to zero: -1.0" == str(e.value))
示例#3
0
def test_ftrl_construct_wrong_nepochs_value():
    with pytest.raises(ValueError) as e:
        noop(Ftrl(nepochs=-1))
    assert ("Argument `nepochs` in Ftrl() constructor cannot be negative: -1"
            == str(e.value))
示例#4
0
def test_ftrl_construct_wrong_double_precision_type():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(double_precision=2))
    assert (
        "Argument `double_precision` in Ftrl() constructor should be a boolean, "
        "instead got <class 'int'>" == str(e.value))
示例#5
0
def test_ftrl_construct_wrong_params_type():
    params = tparams._replace(alpha="1.0")
    with pytest.raises(TypeError) as e:
        Ftrl(params)
    assert ("Expected a float, instead got <class 'str'>" == str(e.value))
示例#6
0
def test_ftrl_pickling_empty_model():
    ft_pickled = pickle.dumps(Ftrl())
    ft_unpickled = pickle.loads(ft_pickled)
    assert ft_unpickled.model == None
    assert ft_unpickled.feature_importances == None
    assert ft_unpickled.params == Ftrl().params
示例#7
0
def test_ftrl_construct_wrong_nepochs_type():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(nepochs=10.0))
    assert ("Argument `nepochs` in Ftrl() constructor should be an integer, "
            "instead got <class 'float'>" == str(e.value))
示例#8
0
def test_ftrl_model_untrained():
    ft = Ftrl()
    assert ft.model == None
示例#9
0
def test_ftrl_set_negative_n_model():
    ft = Ftrl(tparams)
    with pytest.raises(ValueError) as e:
        ft.model = (tmodel[:, {'z': f.z, 'n': -f.n}][:, ['z', 'n']], )
    assert ("Element 0: Values in column `n` cannot be negative" == str(
        e.value))
示例#10
0
def test_ftrl_set_wrong_nbins_value():
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.nbins = 0
    assert ("Value should be positive: 0" == str(e.value))
示例#11
0
def test_ftrl_set_wrong_nepochs_value():
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.nepochs = -10
    assert ("Integer value cannot be negative" == str(e.value))
示例#12
0
def test_ftrl_set_bad_lambda2_value(value):
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.lambda2 = value
    assert ("Value should be greater than or equal to zero: %s" %
            str(value) == str(e.value))
示例#13
0
def test_ftrl_set_bad_alpha_value(value):
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.alpha = value
    assert ("Value should be positive: %s" % str(value) == str(e.value))
示例#14
0
def test_ftrl_set_wrong_interactions_type():
    ft = Ftrl()
    with pytest.raises(TypeError) as e:
        ft.interactions = 2
    assert ("Expected a boolean, instead got <class 'int'>" == str(e.value))
示例#15
0
def test_ftrl_fit_predict_multinomial_vs_binomial():
    ft1 = Ftrl(nbins=10, nepochs=2)
    df_train1 = dt.Frame(range(ft1.nbins))
    df_target1 = dt.Frame([True, False] * 5)
    ft1.fit(df_train1, df_target1)
    p1 = ft1.predict(df_train1)
    ft2 = Ftrl(nbins=10, nepochs=2)
    ft2.labels = ["target", "target2"]
    df_train2 = dt.Frame(range(ft2.nbins))
    df_target2 = dt.Frame(ft2.labels * 5)
    ft2.fit(df_train2, df_target2)
    p2 = ft2.predict(df_train2)
    assert_equals(ft1.model[0], ft2.model[0])
    assert_equals(p1, p2[:, 0])
示例#16
0
def test_ftrl_get_set_model():
    ft = Ftrl(tparams)
    ft.model = (tmodel, )
    assert_equals(ft.model[0], tmodel)
示例#17
0
def test_ftrl_construct_wrong_beta_type():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(beta="1.0"))
    assert ("Argument `beta` in Ftrl() constructor should be a float, instead "
            "got <class 'str'>" == str(e.value))
示例#18
0
def test_ftrl_reset_model():
    ft = Ftrl(tparams)
    ft.model = (tmodel, )
    ft.reset()
    assert ft.model == None
示例#19
0
def test_ftrl_construct_wrong_lambda2_type():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(lambda2="1.0"))
    assert ("Argument `lambda2` in Ftrl() constructor should be a float, "
            "instead got <class 'str'>" == str(e.value))
示例#20
0
def test_ftrl_none_model():
    ft = Ftrl(tparams)
    ft.model = None
    assert ft.model == None
示例#21
0
def test_ftrl_construct_wrong_interactions_type():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(interactions=2))
    assert (
        "Argument `interactions` in Ftrl() constructor should be a boolean, "
        "instead got <class 'int'>" == str(e.value))
示例#22
0
def test_ftrl_fit_no_frame():
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.fit()
    assert ("Training frame parameter is missing" == str(e.value))
示例#23
0
def test_ftrl_construct_unknown_arg():
    with pytest.raises(TypeError) as e:
        noop(Ftrl(c=1.0))
    assert ("Ftrl() constructor got an unexpected keyword argument `c`" == str(
        e.value))
示例#24
0
def test_ftrl_fit_no_target():
    ft = Ftrl()
    with pytest.raises(ValueError) as e:
        ft.fit(None)
    assert ("Target frame parameter is missing" == str(e.value))
示例#25
0
def test_ftrl_construct_wrong_alpha_value():
    with pytest.raises(ValueError) as e:
        noop(Ftrl(alpha=0.0))
    assert ("Argument `alpha` in Ftrl() constructor should be positive: 0.0" ==
            str(e.value))
示例#26
0
def test_ftrl_fit_predict_nones():
    ft = Ftrl()
    ft.fit(None, None)
    df_target = ft.predict(None)
    assert df_target == None
示例#27
0
def test_ftrl_construct_wrong_nbins_value():
    with pytest.raises(ValueError) as e:
        noop(Ftrl(nbins=0))
    assert (
        "Argument `nbins` in Ftrl() constructor should be positive: 0" == str(
            e.value))
示例#28
0
def test_ftrl_fit_predict_from_setters():
    ft = Ftrl(nbins=10)
    df_train = dt.Frame(range(ft.nbins))
    df_target = dt.Frame([True] * ft.nbins)
    # Train `ft` to get a model
    ft.fit(df_train, df_target)
    # Set this model and parameters to `ft2`
    ft2 = Ftrl()
    ft2.params = ft.params
    ft2.model = ft.model
    # Train `ft2` and make predictions
    ft2.fit(df_train, df_target)
    target2 = ft2.predict(df_train)
    # Train `ft` and make predictions
    ft.fit(df_train, df_target)
    target1 = ft.predict(df_train)
    assert_equals(ft.model[0], ft2.model[0])
    assert_equals(target1, target2)
示例#29
0
def test_ftrl_create_default():
    ft = Ftrl()
    assert ft.params == default_params
示例#30
0
def test_ftrl_set_wrong_lambda2_type():
    ft = Ftrl()
    with pytest.raises(TypeError) as e:
        ft.lambda2 = "-1.0"
    assert ("Expected a float, instead got <class 'str'>" == str(e.value))