本文整理汇总了Python中splearn.utils.testing.assert_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_equal函数的具体用法?Python assert_equal怎么用?Python assert_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shape
def test_shape(self):
data = np.arange(4000)
shapes = [(1000, 4),
(200, 20),
(100, 40),
(2000, 2)]
for shape in shapes:
rdd = self.sc.parallelize(data.reshape(shape))
assert_equal(ArrayRDD(rdd).shape, shape)
示例2: test_unblock
def test_unblock(self):
blocked = BlockRDD(self.generate(1000, 5))
unblocked = blocked.unblock()
assert_is_instance(blocked, BlockRDD)
assert_equal(unblocked.collect(), range(1000))
blocked = BlockRDD(self.generate(1000, 5), dtype=tuple)
unblocked = blocked.unblock()
assert_is_instance(blocked, BlockRDD)
assert_equal(unblocked.collect(), range(1000))
示例3: test_same_output
def test_same_output(self):
X, X_rdd = self.make_text_rdd()
local = CountVectorizer()
dist = SparkCountVectorizer()
result_local = local.fit_transform(X).toarray()
result_dist = dist.fit_transform(X_rdd).toarray()
assert_equal(local.vocabulary_, dist.vocabulary_)
assert_array_equal(result_local, result_dist)
示例4: test_ndim
def test_ndim(self):
data = np.arange(4000)
shapes = [(4000),
(1000, 4),
(200, 10, 2),
(100, 10, 2, 2)]
for shape in shapes:
reshaped = data.reshape(shape)
rdd = self.sc.parallelize(reshaped)
assert_equal(ArrayRDD(rdd).ndim, reshaped.ndim)
示例5: test_same_output
def test_same_output(self):
X, X_rdd = self.make_dict_dataset()
local = DictVectorizer()
dist = SparkDictVectorizer()
result_local = local.fit_transform(X)
result_dist = sp.vstack(dist.fit_transform(X_rdd).collect())
assert_equal(local.vocabulary_, dist.vocabulary_)
assert_array_equal(result_local.toarray(), result_dist.toarray())
示例6: test_blocks_number
def test_blocks_number(self):
blocked = BlockRDD(self.generate(1000), bsize=50)
assert_equal(blocked.blocks, 20)
blocked = BlockRDD(self.generate(621), bsize=45)
assert_equal(blocked.blocks, 20)
blocked = BlockRDD(self.generate(100), bsize=4)
assert_equal(blocked.blocks, 30)
blocked = BlockRDD(self.generate(79, 2), bsize=9)
assert_equal(blocked.blocks, 10)
blocked = BlockRDD(self.generate(89, 2), bsize=5)
assert_equal(blocked.blocks, 18)
示例7: test_length
def test_length(self):
blocked = BlockRDD(self.generate(1000))
assert_equal(len(blocked), 1000)
blocked = BlockRDD(self.generate(100))
assert_equal(len(blocked), 100)
blocked = BlockRDD(self.generate(79))
assert_equal(len(blocked), 79)
blocked = BlockRDD(self.generate(89))
assert_equal(len(blocked), 89)
blocked = BlockRDD(self.generate(62))
assert_equal(len(blocked), 62)
示例8: test_same_output_sparse
def test_same_output_sparse(self):
X, X_rdd = self.make_dict_dataset()
local = DictVectorizer(sparse=True)
dist = SparkDictVectorizer(sparse=True)
result_local = local.fit_transform(X)
result_dist = dist.fit_transform(X_rdd)
assert_true(check_rdd_dtype(result_dist, (sp.spmatrix,)))
assert_equal(local.vocabulary_, dist.vocabulary_)
assert_array_equal(result_local.toarray(), result_dist.toarray())
示例9: test_size
def test_size(self):
data = np.arange(4000)
shapes = [(1000, 4),
(200, 20),
(100, 40),
(2000, 2)]
for shape in shapes:
reshaped = data.reshape(shape)
rdd = self.sc.parallelize(reshaped)
size = ArrayRDD(rdd).map(lambda x: x.size).sum()
assert_equal(size, reshaped.size)
assert_equal(ArrayRDD(rdd).size, reshaped.size)
示例10: test_sum
def test_sum(self):
data = np.arange(400).reshape((100, 4))
rdd = self.sc.parallelize(data)
assert_equal(ArrayRDD(rdd).sum(), data.sum())
assert_array_equal(ArrayRDD(rdd).sum(axis=0), data.sum(axis=0))
assert_array_equal(ArrayRDD(rdd).sum(axis=1), data.sum(axis=1))
data = np.arange(600).reshape((100, 3, 2))
rdd = self.sc.parallelize(data)
assert_equal(ArrayRDD(rdd).sum(), data.sum())
assert_array_equal(ArrayRDD(rdd).sum(axis=0), data.sum(axis=0))
assert_array_equal(ArrayRDD(rdd).sum(axis=1), data.sum(axis=1))
assert_array_equal(ArrayRDD(rdd).sum(axis=2), data.sum(axis=2))
示例11: test_transform_with_dtype
def test_transform_with_dtype(self):
data1 = np.arange(400).reshape((100, 4))
data2 = np.arange(200).reshape((100, 2))
rdd1 = self.sc.parallelize(data1, 4)
rdd2 = self.sc.parallelize(data2, 4)
X = DictRDD(rdd1.zip(rdd2), bsize=5)
X2 = X.transform(lambda x: x ** 2, column=0)
assert_equal(X2.dtype, (np.ndarray, np.ndarray))
X2 = X.transform(lambda x: tuple((x ** 2).tolist()), column=0,
dtype=tuple)
assert_equal(X2.dtype, (tuple, np.ndarray))
assert_true(check_rdd_dtype(X2, {0: tuple, 1: np.ndarray}))
X2 = X.transform(lambda x: x ** 2, column=1, dtype=list)
assert_equal(X2.dtype, (np.ndarray, list))
assert_true(check_rdd_dtype(X2, {0: np.ndarray, 1: list}))
X2 = X.transform(lambda a, b: (a ** 2, (b ** 0.5).tolist()),
column=[0, 1], dtype=(np.ndarray, list))
assert_true(check_rdd_dtype(X2, {0: np.ndarray, 1: list}))
X2 = X.transform(lambda b, a: ((b ** 0.5).tolist(), a ** 2),
column=[1, 0], dtype=(list, np.ndarray))
assert_equal(X2.dtype, (np.ndarray, list))
assert_true(check_rdd_dtype(X2, {0: np.ndarray, 1: list}))
示例12: test_convert_tolist
def test_convert_tolist(self):
data = np.arange(400)
rdd = self.sc.parallelize(data, 4)
X = ArrayRDD(rdd, 5)
X_list = X.tolist()
assert_is_instance(X_list, list)
assert_equal(X_list, data.tolist())
data = [2, 3, 5, 1, 6, 7, 9, 9]
rdd = self.sc.parallelize(data, 2)
X = ArrayRDD(rdd)
X_list = X.tolist()
assert_is_instance(X_list, list)
assert_equal(X_list, data)
示例13: test_creation
def test_creation(self):
rdd = self.generate()
blocked = BlockRDD(rdd)
assert_is_instance(blocked, BlockRDD)
assert_equal(blocked.first(), range(10))
assert_equal(blocked.collect(), np.arange(100).reshape(10, 10).tolist())
blocked = BlockRDD(rdd, bsize=4)
assert_is_instance(blocked, BlockRDD)
assert_equal(blocked.first(), range(4))
assert_equal([len(x) for x in blocked.collect()], [4, 4, 2] * 10)
示例14: test_limit_features
def test_limit_features(self):
X, X_rdd = self.make_text_rdd()
params = [{'min_df': .5},
{'min_df': 2, 'max_df': .9},
{'min_df': 1, 'max_df': .6},
{'min_df': 2, 'max_features': 3}]
for paramset in params:
local = CountVectorizer(**paramset)
dist = SparkCountVectorizer(**paramset)
result_local = local.fit_transform(X)
result_dist = sp.vstack(dist.fit_transform(X_rdd).collect())
assert_equal(local.vocabulary_, dist.vocabulary_)
assert_array_equal(result_local.toarray(), result_dist.toarray())
result_dist = sp.vstack(dist.transform(X_rdd).collect())
assert_array_equal(result_local.toarray(), result_dist.toarray())
示例15: test_auto_dtype
def test_auto_dtype(self):
x = np.arange(80).reshape((40, 2))
y = tuple(range(40))
z = list(range(40))
x_rdd = self.sc.parallelize(x, 4)
y_rdd = self.sc.parallelize(y, 4)
z_rdd = self.sc.parallelize(z, 4)
expected = (np.arange(20).reshape(10, 2), tuple(range(10)),
list(range(10)))
rdd = DictRDD([x_rdd, y_rdd, z_rdd])
assert_tuple_equal(rdd.first(), expected)
assert_equal(rdd.dtype, (np.ndarray, tuple, tuple))
assert_true(check_rdd_dtype(rdd, {0: np.ndarray, 1: tuple, 2: tuple}))
rdd = DictRDD([x_rdd, y_rdd, z_rdd], columns=('x', 'y', 'z'))
assert_tuple_equal(rdd.first(), expected)
assert_equal(rdd.dtype, (np.ndarray, tuple, tuple))
assert_true(check_rdd_dtype(rdd, {'x': np.ndarray, 'y': tuple,
'z': tuple}))