|
| 1 | +import unittest |
| 2 | + |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from implicit.als import AlternatingLeastSquares |
| 6 | +from scipy.sparse import csr_matrix |
| 7 | + |
| 8 | + |
| 9 | +class TestImplicit(unittest.TestCase): |
| 10 | + def test_model(self): |
| 11 | + raw = [ |
| 12 | + [0.0, 2.0, 1.5, 1.33333333, 1.25, 1.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 13 | + [0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 14 | + [0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 15 | + [0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 16 | + [0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 17 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 18 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25, 1.2], |
| 19 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333, 1.25], |
| 20 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5, 1.33333333], |
| 21 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.5], |
| 22 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0], |
| 23 | + [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 24 | + ] |
| 25 | + counts = csr_matrix(raw, dtype=np.float64) |
| 26 | + |
| 27 | + model = AlternatingLeastSquares(factors=3) |
| 28 | + model.fit(counts, show_progress=False) |
| 29 | + rows, cols = model.item_factors, model.user_factors |
| 30 | + |
| 31 | + assert not np.isnan(np.sum(cols)) |
| 32 | + assert not np.isnan(np.sum(rows)) |
0 commit comments