Exemple #1
0
    def fit(self, X_train, y_train):
        """ 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}.
        """
        check_consistent_length(X_train, y_train)
        X_train = check_array(X_train,
                              accept_sparse="csc",
                              dtype=np.float64,
                              order="F")
        y_train = _validate_class_labels(y_train)

        self.classes_ = np.unique(y_train)
        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_train.copy()
        i_class1 = (y_train == self.classes_[0])
        y_train[i_class1] = -1
        y_train[-i_class1] = 1

        self.w0_, self.w_, self.V_ = ffm.ffm_als_fit(self, X_train, y_train)
        return self
Exemple #2
0
    def fit(self, X_train, y_train, 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, )

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

        """

        check_consistent_length(X_train, y_train)
        y_train = check_array(y_train, ensure_2d=False, dtype=np.float64)

        X_train = check_array(X_train, accept_sparse="csc", dtype=np.float64,
                              order="F")
        self.n_iter = self.n_iter + n_more_iter

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

        self.w0_, self.w_, self.V_ = ffm.ffm_als_fit(self, X_train, y_train)

        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
Exemple #3
0
    def fit(self, X_train, y_train):
        """ 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}.
        """
        check_consistent_length(X_train, y_train)
        X_train = check_array(X_train, accept_sparse="csc", dtype=np.float64,
                              order="F")
        y_train = _validate_class_labels(y_train)

        self.classes_ = np.unique(y_train)
        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_train.copy()
        i_class1 = (y_train == self.classes_[0])
        y_train[i_class1] = -1
        y_train[-i_class1] = 1

        self.w0_, self.w_, self.V_ = ffm.ffm_als_fit(self, X_train, y_train)
        return self
Exemple #4
0
    def fit(self, X_train, y_train, 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, )
                the targets have to be encodes as {-1, 1}.

        n_more_iter : int
                Number of iterations to continue from the current Coefficients.
        """
        check_consistent_length(X_train, y_train)
        X_train = check_array(X_train,
                              accept_sparse="csc",
                              dtype=np.float64,
                              order="F")
        y_train = _validate_class_labels(y_train)

        self.classes_ = np.unique(y_train)
        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_train.copy()
        i_class1 = (y_train == self.classes_[0])
        y_train[i_class1] = -1
        y_train[~i_class1] = 1

        self.n_iter = self.n_iter + n_more_iter

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

        self.w0_, self.w_, self.V_ = ffm.ffm_als_fit(self, X_train, y_train)

        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
Exemple #5
0
    def fit(self, X_train, y_train, 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, )
                the targets have to be encodes as {-1, 1}.
        
        n_more_iter : int
                Number of iterations to continue from the current Coefficients.
        """
        check_consistent_length(X_train, y_train)
        X_train = check_array(X_train, accept_sparse="csc", dtype=np.float64,
                              order="F")
        y_train = _validate_class_labels(y_train)

        self.classes_ = np.unique(y_train)
        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_train.copy()
        i_class1 = (y_train == self.classes_[0])
        y_train[i_class1] = -1
        y_train[~i_class1] = 1

        self.n_iter = self.n_iter + n_more_iter

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

        self.w0_, self.w_, self.V_ = ffm.ffm_als_fit(self, X_train, y_train)

        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