make_sparse_coded_signal#
- sklearn.datasets.make_sparse_coded_signal(n_samples, *, n_components, n_features, n_nonzero_coefs, random_state=None)[原始碼]#
產生一個訊號,作為字典元素的稀疏組合。
回傳矩陣
Y
、D
和X
,使得Y = XD
,其中X
的形狀為(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 實例或 None,預設值為 None
決定資料集建立的隨機數字產生。傳遞一個 int 以便在多個函式呼叫中獲得可重現的輸出。請參閱詞彙表。
- 回傳:
- data形狀為 (n_samples, n_features) 的 ndarray
編碼後的訊號 (Y)。
- dictionary形狀為 (n_components, n_features) 的 ndarray
具有標準化元件的字典 (D)。
- code形狀為 (n_samples, n_components) 的 ndarray
稀疏碼,使得此矩陣的每一列都恰好有 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)