(self, X, missing_mask)
return X_filled
Train model for max_iters iterations from scratch.
Train model for max_iters iterations from scratch.
Train model for max_iters iterations from scratch .
def solve(self, X, missing_mask):
        """ Train model for max_iters iterations from scratch."""
        X = check_array(X, force_all_finite=False)

        # shape data to fit into keras model
        (n_samples, n_features) = X.shape
        observed_mask = ~missing_mask
        training_indices = list(zip(*np.where(observed_mask)))

        self.user_vecs = np.random.normal(scale=1.0 / self.rank, size=(n_samples, self.rank))
        self.item_vecs = np.random.normal(scale=1.0 / self.rank, size=(n_features, self.rank))

        self.user_bias = np.zeros(n_samples)
        self.item_bias = np.zeros(n_features)
        self.global_bias = np.mean(X[observed_mask])

        for i in range(self.max_iters):
            # to do: early stopping
            if (i + 1) % 10 == 0 and self._v:
                X_reconstruction = self.clip(self.predict_all())
                mae = masked_mae(X_true=X, X_pred=X_reconstruction, mask=observed_mask)
                print("[MatrixFactorization] Iter %d: observed MAE=%0.6f rank=%d" % (i + 1, mae, self.rank))

            np.random.shuffle(training_indices)
            self.sgd(X, training_indices)
            i += 1

        X_filled = X.copy()
        X_filled[missing_mask] = self.clip(self.predict_all()[missing_mask])
        return X_filled
def solve ( self , X , missing_mask ) : X = check_array ( X , force_all_finite = False ) # shape data to fit into keras model ( n_samples , n_features ) = X . shape observed_mask = ~ missing_mask training_indices = list ( zip ( * np . where ( observed_mask ) ) ) self . user_vecs = np . random . normal ( scale = 1.0 / self . rank , size = ( n_samples , self . rank ) ) self . item_vecs = np . random . normal ( scale = 1.0 / self . rank , size = ( n_features , self . rank ) ) self . user_bias = np . zeros ( n_samples ) self . item_bias = np . zeros ( n_features ) self . global_bias = np . mean ( X [ observed_mask ] ) for i in range ( self . max_iters ) : # to do: early stopping if ( i + 1 ) % 10 == 0 and self . _v : X_reconstruction = self . clip ( self . predict_all ( ) ) mae = masked_mae ( X_true = X , X_pred = X_reconstruction , mask = observed_mask ) print ( "[MatrixFactorization] Iter %d: observed MAE=%0.6f rank=%d" % ( i + 1 , mae , self . rank ) ) np . random . shuffle ( training_indices ) self . sgd ( X , training_indices ) i += 1 X_filled = X . copy ( ) X_filled [ missing_mask ] = self . clip ( self . predict_all ( ) [ missing_mask ] ) return X_filled