示例#1
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
示例#2
0
文件: mcmc.py 项目: sebkur/fastFM
    def fit_predict(self, X_train, y_train, X_test, n_more_iter=0):
        """Return average of posterior estimates of the test samples.

        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.task = "regression"
        X_train, y_train, X_test = _validate_mcmc_fit_input(
            X_train, y_train, X_test)

        self.n_iter = self.n_iter + n_more_iter

        if n_more_iter > 0:
            _check_warm_start(self, X_train)
            assert self.prediction_.shape[0] == X_test.shape[0]
            assert self.hyper_param_.shape
            self.warm_start = True
        else:
            self.iter_count = 0

        coef, y_pred = ffm.ffm_mcmc_fit_predict(self, X_train, X_test, y_train)
        self.w0_, self.w_, self.V_ = coef
        self.prediction_ = y_pred
        self.warm_start = False

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

        return y_pred
示例#3
0
文件: mcmc.py 项目: irwenqiang/fastFM
    def fit_predict(self, X_train, y_train, X_test, n_more_iter=0):
        """Return average of posterior estimates of the test samples.

        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.task = "regression"
        X_train, y_train, X_test = _validate_mcmc_fit_input(X_train, y_train,
                                                            X_test)

        self.n_iter = self.n_iter + n_more_iter

        if n_more_iter > 0:
            _check_warm_start(self, X_train)
            assert self.prediction_.shape[0] == X_test.shape[0]
            assert self.hyper_param_.shape
            self.warm_start = True
        else:
            self.iter_count = 0

        coef, y_pred = ffm.ffm_mcmc_fit_predict(self, X_train,
                                                X_test, y_train)
        self.w0_, self.w_, self.V_ = coef
        self.prediction_ = y_pred
        self.warm_start = False

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

        return y_pred