def test_min_count_filter(self): X = np.array([[1.0, 0.0, 0.0], [2.0, 1.0, 0.0], [3.0, 0.0, 0.0], [2.0, 1.0, 0.0], [4.0, 1.0, 0.0], [6.0, 9.0, 0.0]]) filt = MinCountFilter(min_count=5) Xt = filt.fit_transform(X) # expected X Xe = X[:,0][np.newaxis].T assert_array_equal(Xt, Xe)
def test_min_count_filter_sparse(self): X = sp.csr_matrix([[1.0, 0.0, 0.0], [2.0, 1.0, 0.0], [3.0, 0.0, 0.0], [2.0, 1.0, 0.0], [4.0, 1.0, 0.0], [6.0, 9.0, 0.0]]) filt = MinCountFilter(min_count=5) Xt = filt.fit_transform(X) # expected X Xe = X[:,0] assert Xt.shape == (6,1) # __eq__ is not properly implemented for sparse matrices # so apply this trick assert (Xt - Xe).nnz == 0