ibayer / fastFM

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

Fit complaining about both dense/sparse #150

Closed pugantsov closed 5 years ago

pugantsov commented 5 years ago

I'm trying to run ALS regression and I ran into the following error:

Traceback (most recent call last):
  File "model_fastfm.py", line 13, in <module>
    fm.fit(X_train, y_train)
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/als.py", line 86, in fit
    order="F")
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/validation.py", line 29, in wrapper
    raise TypeError('A dense matrix was passed in, but sparse'
TypeError: A dense matrix was passed in, but sparsedata is required.

So I then converted the ndarray types to their sparse matrix equivalent and got this:

Traceback (most recent call last):
  File "model_fastfm.py", line 13, in <module>
    fm.fit(X_train, y_train)
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/als.py", line 83, in fit
    y_train = check_array(y_train, ensure_2d=False, dtype=np.float64)
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/validation.py", line 31, in wrapper
    result = func(*args, **kwargs)
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/validation.py", line 160, in check_array
    copy, force_all_finite)
  File "/home/alex/anaconda3/envs/recsys/lib/python3.6/site-packages/fastFM/validation.py", line 64, in _ensure_sparse_format
    raise TypeError('A sparse matrix was passed, but dense '
TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.

I'm now a little confused as to what the fit function is expecting for input/where I've went wrong. Any light on this would be helpful, thanks.

ibayer commented 5 years ago

@ajhepburn Please have a look at https://github.com/ibayer/fastFM/blob/master/fastFM/tests/test_als.py

If this doesn't help please provide a self contained example.

Using https://scikit-learn.org/stable/modules/classes.html#samples-generator might be helpful to generate a data set.

ibayer commented 5 years ago

please reopen if the issue persist