(self, X, observed_mask, check_para=True)
return X_filled
Complete the matrix.

        Parameters
        ----------
        X: array
            The complete data matrix. Shape like [n_samples, n_features]

        observed_mask: {list, np.ndarray}
            The mask matrix of X. the matrix should have the same shape with X.
            There must be only 1 and 0 in the matrix, in which, 1 means the corresponding element is known,
            otherwise, it will be cheated as an unknown element.

        Returns
        -------
        X_filled: array
            The completed matrix.
Complete the matrix.
Complete the matrix .
def impute(self, X, observed_mask, check_para=True):
        """Complete the matrix.

        Parameters
        ----------
        X: array
            The complete data matrix. Shape like [n_samples, n_features]

        observed_mask: {list, np.ndarray}
            The mask matrix of X. the matrix should have the same shape with X.
            There must be only 1 and 0 in the matrix, in which, 1 means the corresponding element is known,
            otherwise, it will be cheated as an unknown element.

        Returns
        -------
        X_filled: array
            The completed matrix.
        """
        X = check_array(X, force_all_finite=False)
        observed_mask = np.asarray(observed_mask)
        if check_para:
            obrT = np.asarray(observed_mask)
            assert obrT.shape[0] == X.shape[0] and obrT.shape[1] == X.shape[1]
            ue = np.unique(obrT)
            assert len(ue) == 2
            assert 0 in ue
            assert 1 in ue
        missing_mask = 1 - observed_mask
        X_filled = X * missing_mask
        for i in range(self.max_iters):
            # deviation from original svdImpute algorithm:
            # gradually increase the rank of our approximation
            if self.gradual_rank_increase:
                curr_rank = min(2 ** i, self.rank)
            else:
                curr_rank = self.rank
            tsvd = TruncatedSVD(curr_rank, algorithm=self.svd_algorithm)
            X_reduced = tsvd.fit_transform(X_filled)
            X_reconstructed = tsvd.inverse_transform(X_reduced)
            X_reconstructed = self._clip(X_reconstructed)

            converged = self._converged(
                X_old=X_filled,
                X_new=X_reconstructed,
                missing_mask=missing_mask)
            X_filled = X_reconstructed * missing_mask + X * observed_mask
            if converged:
                break
        return X_filled
def impute ( self , X , observed_mask , check_para = True ) : X = check_array ( X , force_all_finite = False ) observed_mask = np . asarray ( observed_mask ) if check_para : obrT = np . asarray ( observed_mask ) assert obrT . shape [ 0 ] == X . shape [ 0 ] and obrT . shape [ 1 ] == X . shape [ 1 ] ue = np . unique ( obrT ) assert len ( ue ) == 2 assert 0 in ue assert 1 in ue missing_mask = 1 - observed_mask X_filled = X * missing_mask for i in range ( self . max_iters ) : # deviation from original svdImpute algorithm: # gradually increase the rank of our approximation if self . gradual_rank_increase : curr_rank = min ( 2 ** i , self . rank ) else : curr_rank = self . rank tsvd = TruncatedSVD ( curr_rank , algorithm = self . svd_algorithm ) X_reduced = tsvd . fit_transform ( X_filled ) X_reconstructed = tsvd . inverse_transform ( X_reduced ) X_reconstructed = self . _clip ( X_reconstructed ) converged = self . _converged ( X_old = X_filled , X_new = X_reconstructed , missing_mask = missing_mask ) X_filled = X_reconstructed * missing_mask + X * observed_mask if converged : break return X_filled