Esempio n. 1
0
    def fit(self, X, y):
        """ Fit model with specified loss.

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

        y : float | ndarray, shape = (n_samples, )

                the targets have to be encodes as {-1, 1}.
        """
        y = _validate_class_labels(y)
        self.classes_ = np.unique(y)
        if len(self.classes_) != 2:
            raise ValueError("This solver only supports binary classification"
                             " but the data contains"
                             " class: %r" % self.classes_)

        # fastFM-core expects labels to be in {-1,1}
        y_train = y.copy()
        i_class1 = (y_train == self.classes_[0])
        y_train[i_class1] = -1
        y_train[-i_class1] = 1

        check_consistent_length(X, y)
        y = y.astype(np.float64)
        X = X.T
        X = check_array(X, accept_sparse="csc", dtype=np.float64)

        self.w0_, self.w_, self.V_ = ffm.ffm_sgd_fit(self, X, y)
        return self
Esempio n. 2
0
    def fit(self, X, y, n_more_iter=0):
        """ Fit model with specified loss.

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

        y : float | ndarray, shape = (n_samples, )

        """

        check_consistent_length(X, y)
        y = check_array(y, ensure_2d=False, dtype=np.float64)

        # 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)

        self.n_iter = self.n_iter + n_more_iter

        if n_more_iter > 0:
            _check_warm_start(self, X.T)
            self.warm_start = True

        self.w0_, self.w_, self.V_ = ffm.ffm_sgd_fit(self, X, y)

        if self.iter_count != 0:
            self.iter_count = self.iter_count + n_more_iter
        else:
            self.iter_count = self.n_iter

        # reset to default setting
        self.warm_start = False
        return self
Esempio n. 3
0
    def fit(self, X, y):
        """ Fit model with specified loss.

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

        y : float | ndarray, shape = (n_samples, )

        """

        check_consistent_length(X, y)
        y = check_array(y, ensure_2d=False, dtype=np.float64)
        X = X.T
        X = check_array(X, accept_sparse="csc", dtype=np.float64)

        self.w0_, self.w_, self.V_ = ffm.ffm_sgd_fit(self, X, y)
        return self
Esempio n. 4
0
    def fit(self, X, y):
        """ Fit model with specified loss.

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

        y : float | ndarray, shape = (n_samples, )

        """

        check_consistent_length(X, y)
        y = check_array(y, ensure_2d=False, dtype=np.float64)

        # 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)

        self.w0_, self.w_, self.V_ = ffm.ffm_sgd_fit(self, X, y)
        return self
Esempio n. 5
0
    def fit(self, X, y):
        """ Fit model with specified loss.

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

        y : float | ndarray, shape = (n_samples, )

        """

        check_consistent_length(X, y)
        y = check_array(y, ensure_2d=False, dtype=np.float64)

        # 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)

        self.w0_, self.w_, self.V_ = ffm.ffm_sgd_fit(self, X, y)
        return self