Skip to content

Add fit_predict to FactorizationMachine #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions fastFM/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ def predict(self, X_test):
assert sp.isspmatrix_csc(X_test)
assert X_test.shape[1] == len(self.w_)
return ffm.ffm_predict(self.w0_, self.w_, self.V_, X_test)

def fit_predict(self, X_train, y_train, X_test, n_more_iter=0):
"""Return predictions after calling fit method

Parameters
----------
X_train : scipy.sparse.csc_matrix, (n_samples, n_features)

y_train : array, shape (n_samples)

X_test : scipy.sparse.csc_matrix, (n_test_samples, n_features)

n_more_iter : int
Number of iterations to continue from the current Coefficients.

Returns
-------
T : array, shape (n_test_samples)
"""
self.fit(X_train, y_train, n_more_iter=n_more_iter)
return self.predict(X_test)


class BaseFMClassifier(FactorizationMachine, ClassifierMixin):
Expand Down