make_sparse_coded_signal#

sklearn.datasets.make_sparse_coded_signal(n_samples, *, n_components, n_features, n_nonzero_coefs, random_state=None)[source]#

生成作为字典元素的稀疏组合的信号。

返回矩阵 Y, DX,其中 Y = XDX 的形状为 (n_samples, n_components)D 的形状为 (n_components, n_features),且 X 的每一行都恰好有 n_nonzero_coefs 个非零元素。

用户指南中阅读更多内容。

参数:
n_samplesint

要生成的样本数量。

n_componentsint

字典中的分量数量。

n_featuresint

要生成的数据集的特征数量。

n_nonzero_coefsint

每个样本中活动的(非零)系数数量。

random_stateint, RandomState instance or None, default=None

确定数据集创建的随机数生成。传递一个 int 值以在多次函数调用中获得可重现的输出。请参阅词汇表

返回:
datandarray of shape (n_samples, n_features)

编码信号(Y)。

dictionaryndarray of shape (n_components, n_features)

具有归一化分量的字典(D)。

codendarray of shape (n_samples, n_components)

稀疏代码,该矩阵的每一列恰好有 n_nonzero_coefs 个非零项(X)。

示例

>>> from sklearn.datasets import make_sparse_coded_signal
>>> data, dictionary, code = make_sparse_coded_signal(
...     n_samples=50,
...     n_components=100,
...     n_features=10,
...     n_nonzero_coefs=4,
...     random_state=0
... )
>>> data.shape
(50, 10)
>>> dictionary.shape
(100, 10)
>>> code.shape
(50, 100)