def fit(self, X, pairs): """ Fit model with specified loss. Parameters ---------- X : scipy.sparse.csc_matrix, (n_samples, n_features) y : float | ndarray, shape = (n_compares, 2) Each row `i` defines a pair of samples such that the first returns a high value then the second FM(X[i,0]) > FM(X[i, 1]). """ # The sgd solver expects a transposed design matrix in column major # order (csc_matrix). X = X.T # creates a copy X = check_array(X, accept_sparse="csc", dtype=np.float64) assert_all_finite(pairs) pairs = pairs.astype(np.float64) # check that pairs contain no real values assert_array_equal(pairs, pairs.astype(np.int32)) assert pairs.max() <= X.shape[1] assert pairs.min() >= 0 self.w0_, self.w_, self.V_ = ffm.ffm_fit_sgd_bpr(self, X, pairs) return self