ibayer / fastFM

fastFM: A Library for Factorization Machines
http://ibayer.github.io/fastFM
Other
1.07k stars 206 forks source link

Check pairs range failed when fitting BPR #146

Closed dennisylyung closed 5 years ago

dennisylyung commented 5 years ago

When fitting BPR, I encountered this error:

AssertionError                            Traceback (most recent call last)
<ipython-input-427-3044c83cef63> in <module>
      1 from fastFM import bpr
      2 fm = bpr.FMRecommender(n_iter=1000, init_stdev=0.1, rank=2, l2_reg_w=0.1, l2_reg_V=0.5)
----> 3 fm.fit(X_train, pairs_train)
      4 y_pred = fm.predict(X_test)

/usr/local/lib/python3.5/dist-packages/fastFM/bpr.py in fit(self, X, pairs)
     90         # check that pairs contain no real values
     91         assert_array_equal(pairs, pairs.astype(np.int32))
---> 92         assert pairs.max() <= X.shape[1]
     93         assert pairs.min() >= 0
     94         self.w0_, self.w_, self.V_ = ffm.ffm_fit_sgd_bpr(self, X, pairs)

AssertionError: 

The assert block should be making sure that the pairs are correct indices of X, by checking if the range of values in pairs fall within the number of samples of X However, X.shape[1] represents the number of features, instead of number of samples Should it be assert pairs.max() <= X.shape[0] instead? for reference, the matrix X used in my code has a shape of (9276, 5992), i.e. more number of samples than number of features