Beispiel #1
0
def test_fsslim_init_warn_k_positive():
    try:
        algo = slim.fsSLIM(k=0)
    except ValueError:
        pass  # this is fine
    try:
        algo = slim.fsSLIM(k=-1)
    except ValueError:
        pass  # this is fine
Beispiel #2
0
def test_fsslim_simple_predict():
    algo = slim.fsSLIM(k=3, selector=simple_fs_selector)
    algo.fit(simple_ratings)

    res = algo.predict_for_user(1, [7])

    assert res is not None
    assert len(res) == 1
    assert 7 in res.index
    assert not np.isnan(res.loc[7])
Beispiel #3
0
def test_fsslim_simple_predict_binary():
    algo = slim.fsSLIM(regularization=(.005, .005),
                       binary=True,
                       k=3,
                       selector=simple_fs_selector)
    algo.fit(simple_ratings)

    res = algo.predict_for_user(1, [7])

    assert res is not None
    assert len(res) == 1
    assert 7 in res.index
    assert not np.isnan(res.loc[7])
Beispiel #4
0
def test_fsslim_unordered_predict():
    algo = slim.fsSLIM(k=3, selector=simple_fs_selector)
    algo.fit(simple_ratings)

    res = algo.predict_for_user(1, [7, 6, 9])

    assert res is not None
    assert len(res) == 3
    assert 7 in res.index
    assert 6 in res.index
    assert 9 in res.index
    assert res.index[0] == 7
    assert res.index[1] == 6
    assert res.index[2] == 9
    assert not np.isnan(res.loc[7])
Beispiel #5
0
def test_fsslim_train():
    algo = slim.fsSLIM(k=3, selector=simple_fs_selector)
    algo.fit(simple_ratings)

    assert isinstance(algo.item_index_, pd.Index)
    assert isinstance(algo.user_index_, pd.Index)

    # Diagonal of the coefficient matrix is 0 and there are some values
    assert all(algo.coefficients_.diagonal() == 0)
    assert all(np.logical_not(np.isnan(algo.coefficients_.data)))
    assert len(algo.coefficients_.data) > 0

    # 7 is associated with 9
    seven, nine = algo.item_index_.get_indexer([7, 9])
    _log.info('seven: %d', seven)
    _log.info('nine: %d', nine)
    assert algo.coefficients_[seven, nine] > 0
Beispiel #6
0
def test_fsslim_train_smoke_test():
    algo = slim.fsSLIM(k=4)
    algo.fit(simple_ratings)
Beispiel #7
0
def test_fsslim_init_warn_invalid_selector():
    try:
        algo = slim.fsSLIM(selector=slim.SLIM())
    except ValueError:
        pass  # this is fine
Beispiel #8
0
def test_fsslim_init_warn_no_selector():
    try:
        algo = slim.fsSLIM(selector=None)
    except ValueError:
        pass  # this is fine
Beispiel #9
0
def test_fsslim_init_warn_negative_regularization():
    try:
        algo = slim.fsSLIM(-1)
    except ValueError:
        pass  # this is fine
Beispiel #10
0
def test_fsslim_init():
    algo = slim.fsSLIM()