shuffle_arrays_unison: 以一致的方式打乱数组

一个用于 NumPy 数组的统一函数。

> from mlxtend.preprocessing import shuffle_arrays_unison

示例 1 - 对 Pandas 数据框进行缩放

import numpy as np
from mlxtend.preprocessing import shuffle_arrays_unison
X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
y = np.array([1, 2, 3])
print('X:\n%s' % X)
print('y:\n%s' % y)

X:
[[1 2 3]
 [4 5 6]
 [7 8 9]]
y:
[1 2 3]
X2, y2 = shuffle_arrays_unison(arrays=[X, y], random_seed=3)
print('X2:\n%s' % X2)
print('y2:\n%s' % y2)

X2:
[[4 5 6]
 [1 2 3]
 [7 8 9]]
y2:
[2 1 3]

API

shuffle_arrays_unison(arrays, random_seed=None)

Shuffle NumPy arrays in unison.

Parameters

Returns

Examples

>>> import numpy as np
>>> from mlxtend.preprocessing import shuffle_arrays_unison
>>> X1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> y1 = np.array([1, 2, 3])
>>> X2, y2 = shuffle_arrays_unison(arrays=[X1, y1], random_seed=3)
>>> assert(X2.all() == np.array([[4, 5, 6], [1, 2, 3], [7, 8, 9]]).all())
>>> assert(y2.all() == np.array([2, 1, 3]).all())
>>>

For more usage examples, please see https://rasbt.github.io/mlxtend/user_guide/preprocessing/shuffle_arrays_unison/