コード例 #1
0
def test_slim_simple_predict():
    algo = slim.SLIM()
    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])
コード例 #2
0
def test_slim_simple_predict_binary():
    algo = slim.SLIM(regularization=(.05, .05), binary=True)
    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])
コード例 #3
0
def test_slim_multiple_predict():
    algo = slim.SLIM()
    algo.fit(simple_ratings)

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

    assert res is not None
    assert len(res) == 2
    assert 6 in res.index
    assert 7 in res.index
    assert res.index[0] == 6
    assert res.index[1] == 7
    assert not np.isnan(res.loc[7])
コード例 #4
0
def test_slim_train_big():
    algo = slim.SLIM()
    algo.fit(ml_ratings)

    # 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

    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])
コード例 #5
0
def test_slim_unordered_predict():
    algo = slim.SLIM()
    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])
コード例 #6
0
def test_slim_train_binary():
    algo = slim.SLIM(regularization=(.05, .05), binary=True)
    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
コード例 #7
0
def test_slim_predict_binary_big_parallel():
    algo = slim.SLIM(binary=True, nprocs=5)
    algo.fit(ml_ratings)

    # 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

    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])

    res = algo.predict_for_user(1)

    assert res is not None
    assert len(res) == len(ml_ratings.item.unique())
コード例 #8
0
def test_slim_train_smoke_test():
    algo = slim.SLIM()
    algo.fit(simple_ratings)
コード例 #9
0
def test_slim_init_warn_negative_regularization():
    try:
        algo = slim.SLIM(-1)
    except ValueError:
        pass  # this is fine
コード例 #10
0
def test_slim_init():
    algo = slim.SLIM()
コード例 #11
0
def test_fsslim_init_warn_invalid_selector():
    try:
        algo = slim.fsSLIM(selector=slim.SLIM())
    except ValueError:
        pass  # this is fine